Template2
Template2 copied to clipboard
Allow plugins being preloaded/embedded in a bundle [rt.cpan.org #77554]
Migrated from rt.cpan.org#77554 (status was 'new')
Requestors:
Attachments:
From [email protected] on 2012-05-31 09:32:52:
Hi,
during a PoC generating C code for GLib's GDBus-Object infrastructure I needed some handy routines I wanted to provide via TT plugin - but not freely usable, because their context is limited to generated code from the introspection information.
So I created "private" packages in the code generator per language - but T:P always wanted a file. The attached patch accepts plugins which are loaded already, too (must derived from T:P).
/Jens
--- lib/Template/Plugins.pm.orig 2012-01-21 08:19:04.000000000 +0000
+++ lib/Template/Plugins.pm
@@ -189,7 +189,7 @@ sub _load {
$file =~ s|::|/|g;
$self->debug("loading $module.pm (PLUGIN_NAME)")
if $self->{ DEBUG };
- $ok = eval { require "$file.pm" };
+ $ok = eval { $module->isa("Template::Plugin") or require "$file.pm" };
$error = $@;
}
else {
@@ -203,7 +203,7 @@ sub _load {
$self->debug("loading $file.pm (PLUGIN_BASE)")
if $self->{ DEBUG };
- $ok = eval { require "$file.pm" };
+ $ok = eval { $pkg->isa("Template::Plugin") or require "$file.pm" };
last unless $@;
$error .= "$@\n"
Needs a PR
@rehsack I opened #196 PR for this. Is there a reason we wouldn't check %INC and only load if it's not there? the @ISA thing makes me nervous even though it looks perfectly safe.
@toddr I think that's pretty clear described in the ticket. It's quite usual to have multiple packages in one file. Checking %INC is superfluous.
Ok good point. We're still going to want tests before merging this. Thanks!
That's ages ago - can't promise anything. Need to work on my modules either ;) The test should be easy - maybe you can spend some effort ...
Sorry, I wasn’t saying you needed to do it. I was saying it needed to be done before we merge
@toddr Understood, no worries. I just could have quoted Tim Bunce who said: "Don't wait for ... coming from me. It won't." - I just wanted to show the red flag before anyone waits for me (implicitly).