Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: SVN::Client subclassing issue

by tj_thompson (Monk)
on Sep 27, 2011 at 19:54 UTC ( #928165=note: print w/ replies, xml ) Need Help??


in reply to Re^2: SVN::Client subclassing issue
in thread SVN::Client subclassing issue

Make your class has-a-SVN::Client not is-a-SVN::Client?

This is what I had in mind. I was going to subclass initially because I wanted some functions to 'fall through' to the SVN::Client class without having to wrap each one. This should be easy enough to do from another object, but it's not something I've done before.

So assuming my new Foo class is called with a function that is not part of the package, let's say Foo->cat. Foo does not have a cat function, but Foo does have a SVN::Client object. I'd like to pass a call to a function that does not exist in the current package to be handled by the SVN::Client object. What is the proper/elegant way to do this?


Comment on Re^3: SVN::Client subclassing issue
Re^4: SVN::Client subclassing issue (AUTOLOAD)
by tye (Cardinal) on Sep 27, 2011 at 20:20 UTC
    our $AUTOLOAD; sub AUTOLOAD { my( $self )= shift @_; my( $class, $method )= $AUTOLOAD =~ /^(.+)(?:'|::)(.+)$/ or die "Invalid method name: $AUTOLOAD"; return if 'DESTROY' eq $method; die "Can't call internal method, $method, via ", __PACKAGE__, $/ if $method =~ /^_/; return $self->{whatever}->$method( @_ ); }

    Not so much "proper" or "elegant" but a thrown-together example but also not "improper" nor particularly "inelegant".

    - tye        

Re^4: SVN::Client subclassing issue
by Anonymous Monk on Sep 27, 2011 at 20:21 UTC
    See AUTOLOAD section of Modern Perl: the free book, and mind the caveats

    Assuming hashref has-a 'SVN::Client'

    sub AUTOLOAD { my ($name) = our $AUTOLOAD =~ /::(\w+)$/; my $method = sub { my $self = shift; return $self->{'SVN::Client'}->$name( @_ ); } no strict 'refs'; *{ $AUTOLOAD } = $method; return $method->( @_ ); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928165]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-12-25 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls