in reply to AUTOLOAD question

Declare it with our (or use vars '$AUTOLOAD'... I think). So something like...
sub AUTOLOAD { my $self = shift; our $AUTOLOAD; # I usually do... #$AUTOLOAD =~ s/(?:\w+::)+//; # ... but here's your pattern $AUTOLOAD =~ s/.*://; if ($self->{xmms}->can($AUTOLOAD)) { $self->{xmms}->$AUTOLOAD; } else { die "$AUTOLOAD not a valid method!"; } }
Of course, you'll probably need to modify that and add some (different|better|more appropriate) error testing for invalid method calls.

Replies are listed 'Best First'.
Re: Re: AUTOLOAD question
by ysth (Canon) on Nov 30, 2003 at 01:50 UTC
    It's also good to note that can() returns a coderef, so you can just call it:
    &{$self->{xmms}->can($AUTOLOAD) || die "no $AUTOLOAD method"}($self->{ +xmms});
    or create a stub in your module, so each method only goes through AUTOLOAD the first time it is called:
    if (my $methodref = $self->{xmms}->can($AUTOLOAD)) { { no strict 'refs'; *$AUTOLOAD = sub { unshift @_, shift()->{xmms}; goto &$methodref + }; } $methodref->($self->{xmms}); }
    (Untested, but should give you the idea.)