# can - Help UNIVERSAL::can() cope with our AUTOLOADed methods sub can { my ($self, $method) = @_; my $subref = $self->SUPER::can($method); return $subref if $subref; # can found it; it's a real method # Method doesn't currently exist; should it, though? return unless exists $self->{$method}; # Return an anon sub that will work when it's eventually called sub { my $self = $_[0]; # The method is being called. The real method may have been # created in the meantime; if so, don't call AUTOLOAD again my $subref = $self->SUPER::can($method); goto &$subref if $subref; $AUTOLOAD=$method; goto &AUTOLOAD }; }