[Pdx-pm] [build in defaults to method calls from the outside] need some help thinking thru this one

chromatic chromatic at wgz.org
Mon Jul 23 22:20:25 PDT 2007


On Monday 23 July 2007 22:06:24 Michael G Schwern wrote:

> To complete the illusion, override can() so it can answer correctly for the
> autoloaded methods which haven't been called yet.
>
> sub can {
>         my($self, $method) = @_;
>
>         return 1 if $self->can($method);
>         return 1 if $self->{bi}->can($method);
>
>         return 0;
> }

Nit: can() returns a subroutine reference or undef, never a boolean.

sub can
{
    my ($self, $method) = @_;
    my $meth_ref = $self->can($method);
    return $meth_ref if $meth_ref;
   return $self->{bi}->can($method);
}

-- c


More information about the Pdx-pm-list mailing list