1 [[!meta title="Cannot manage to inject preprocess_tag"]]
4 I am trying to write a plugin that changes the way the
5 [[ikiwiki/directive/tag]] [[ikiwiki/directive]] works, and I am trying to do so
6 by using the [[inject|plugins/write/#index81h3]] function. The piece of code
7 that should (if I understood well the `inject` function) do the trick is :
11 name => 'IkiWiki::Plugin::tag::preprocess_tag',
12 call => \&my_preprocess_tag
16 Howere, this does not change anything about the effect of the `tag` directive.
18 I have tried some variants, like calling `inject` outside the `import`
19 function, or calling `IkiWiki::loadplugin("tag");` to ensure that the
20 [[plugins/tag]] is loaded, but none of these things work. Any idea?
22 *Disclaimer:* although proficient in several languages, I am a beginner in Perl.
24 Here is the full code of (a very early version of) my plugin.
28 package IkiWiki::Plugin::parenttag;
34 my $orig_preprocess_tag=\&preprocess_tag;
38 name => 'IkiWiki::Plugin::tag::preprocess_tag',
39 call => \&my_preprocess_tag
43 sub my_preprocess_tag(@) {
44 print "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nWorking!\n";
53 > I managed to replace the tag original `preprocess_tag` function, using a different approach than using `inject`:
55 > my $orig_preprocess_tag;
58 > IkiWiki::loadplugin("tag");
59 > $orig_preprocess_tag = \&{$IkiWiki::hooks{preprocess}{tag}{call}};
60 > hook(type => "preprocess", id => "tag", call => \&my_preprocess_tag);
63 > And later on, I can call the original `preprocess_tag` function using:
65 > $orig_preprocess_tag->(...)
67 > The problem is that I am digging into `IkiWiki.pm` package to extract data from `IkiWiki::hooks`, which is not guaranteed to work in the future, contrary to `inject`.
71 > - how ugly is my solution?
72 > - is it possible to use `inject` to replace the `IkiWiki::Plugin::tag::preprocess_tag` function?