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


Reply via email to