Ok, who the patch pumpkin? I've worked on a patch for this LOAD_PERL bug. I'm not exactly sure what the patch procedure is. Do we have one? Let me know if we do, and I'll rework the format. Otherwise, attached is a tar.gz file with two patch files, and a new Factory.pm file that goes in the ./lib/Template directory.
I tested and it seems to work, but of course the "mileage" is low
so your mileage may vary.
BTW, in the course of testing this patch, I ran across a configuration
option (PLUGIN_FACTORY) that I didn't see documented anywhere and only
used in two files (t/leak.t and lib/Template/Plugins.pm). I doubt that if
PLUGIN_FACTORY and LOAD_PERL were both enabled, you'd get the desired
behavior. But that's left as an exercise to the reader.
Quoting Lyle Brooks ([EMAIL PROTECTED]):
>
> ...or... have _load() return a newly created "Factory" object (we'd
> have to create such a class, because I don't think such a class currently
> exists within TT2) instead of a string. Then _load could set an attribute
> of the factory object.
>
> then factory->new() would do something like..
>
> sub new {
> my $self = shift;
>
> my $native_factory = $self->native();
>
> if ($self->is_plugin) {
> $native_factory->new($self->context, $self->args);
> }
> else {
> $native_factory->new($self->args);
> }
>
> }
>
>
>
> hmmm... even better yet.
>
> have _load() create and return a Factory object (which would be either a
> Factory::NonPlugin or a Factory::Plugin object (both of which would
> inherit from a common base Factory object)
>
> Define Factory::NonPlugin::new() like so...
>
> sub new {
> my $self = shift;
>
> my $native_factory = $self->native(); # the string currently returned
> # by _load()
> $native_factory->new($self->args);
> }
>
> and Factory::Plugin::new like so...
>
> sub new {
> my $self = shift;
>
> my $native_factory = $self->native(); # the string currently returned
> # by _load()
> $native_factory->new($self->context, $self->args);
> }
>
>
> then from fetch()
>
> $plugin = $factory->new(@$args);
>
>
> becomes
>
> $plugin = $factory->new(@$args);
>
>
> and everything is "self-aware"
>
>
> Quoting Craig Barratt ([EMAIL PROTECTED]):
> > > While running ttree I've run into what appears to be a bug when
> > > using the LOAD_PERL option. I'm using v2.04
> >
> > This does appear to be a bug. Your analysis looks correct. Nice work!
> >
> > There are several possible fixes, but I'm not sure which is most
> > elegant.
> >
> > One way is to make _load return a flag that says whether it is a
> > plain perl module or not. fetch() could then save this flag in a
> > new hash (eg: $self->{ FACTORY_IS_PLAIN_MODULE }->{ $name }). Or,
> > based on the _load return flag, fetch() could save plain modules
> > in $self->{ FACTORY_PLAIN }->{ $name }, and normal modules in
> > $self->{ FACTORY }->{ $name }. In either case, shifting @args
> > should be removed from _load(), and fetch() only needs to
> > unshift $context onto @args for the case of a real plugin.
> >
> > Craig
>
> _______________________________________________
> templates mailing list
> [EMAIL PROTECTED]
> http://www.template-toolkit.org/mailman/listinfo/templates
Template.patch.tar.gz
Description: application/tar-gz
