in reply to AUTOLOAD question
However, in your case, I would avoid using AUTOLOAD and recommend the following:use vars '$AUTOLOAD'; sub AUTOLOAD { my ($self) = @_; my ($method); ($method = $AUTOLOAD) =~ s/.*://; if ($self->{xmms}->can($method)) { $self->{xmms}->$method; } else { # whatever } }
Here, you auto-generate only the methods you want. This way misspelled method calls won't get swallowed up by AUTOLOAD. (i.e, you get the appropriate error message from Perl itself, rather than needing AUTOLOAD to die appropriately).{ no strict 'refs'; for my $method (qw/is_paused is_playing play pause stop/) { *$method = sub { $_[0]->{xmms}->$method }; } }
blokhead
|
|---|