Template2 icon indicating copy to clipboard operation
Template2 copied to clipboard

Allow plugins being preloaded/embedded in a bundle [rt.cpan.org #77554]

Open atoomic opened this issue 7 years ago • 8 comments

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

atoomic avatar Oct 05 '18 16:10 atoomic

--- 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" 

toddr avatar Oct 05 '18 19:10 toddr

Needs a PR

toddr avatar Oct 05 '18 19:10 toddr

@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 avatar Oct 08 '18 23:10 toddr

@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.

rehsack avatar Oct 09 '18 06:10 rehsack

Ok good point. We're still going to want tests before merging this. Thanks!

toddr avatar Oct 09 '18 20:10 toddr

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 ...

rehsack avatar Oct 10 '18 06:10 rehsack

Sorry, I wasn’t saying you needed to do it. I was saying it needed to be done before we merge

toddr avatar Oct 10 '18 11:10 toddr

@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).

rehsack avatar Oct 10 '18 16:10 rehsack