[Pdx-pm] Pod::Coverage Weirdness with Class::Trait
Ovid
publiustemp-pdxpm at yahoo.com
Wed Feb 15 07:46:57 PST 2006
--- Richard Clamp <richardc at unixbeard.net> wrote:
> no warnings 'redefine';
> eval qq{
> package $package;
> sub $method_label { $method(\@_) }
> };
>
> To make Pod::Coverage happy that would be done as method injection,
> more like:
>
> {
> no strict 'refs';
> *{"$package\::$method_label"} = \&{$method};
> }
>
> But I only just met Class::Trait so I'm only speculating as to
> whether that's really equivalent.
As the current maintainer of Class::Trait, I'm embarrassed I forgot
about that. Yeah, that's what could be causing the Pod::Coverage
behavior. In fact, because traits are generally there for creating
public methods and not just for importing helper functions, I would
even argue that the Pod::Coverage behavior is correct.
As for the method injection in lieue of the eval, it fails in the case
of $self->SUPER::method(@_) because the trait methods get confused and
thing the class to redispatch to is the calling code (main:: in the
case of tests) instead of the proper SUPER class.
Because SUPER binds a bit too early for me, there's actually an
AUTOLOAD in Class::Trait::Base which traps and fixes this behavior, but
it relies on the eval(). Ugly, I know. Here's the relevant code:
# if someone is attempting a call to
# SUPER, then we need to handle this.
if ( my ($super_method) = $auto_load =~ /(SUPER::.*)/ ) {
# get our arguemnts
my ( $self, @args ) = @_;
# lets get the intended method name
$super_method = scalar( caller 1 ) . '::' . $super_method;
return $self->$super_method(@args);
}
Now that I look at this, I wonder if searching the $self inheritance
tree would be better than checking caller? I'm not sure. I didn't
write this part of Class::Trait so I don't know the subtleties here.
Cheers,
Ovid
--
If this message is a response to a question on a mailing list, please send follow up questions to the list.
Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
More information about the Pdx-pm-list
mailing list