tj_thompson has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
I'm trying to subclass SVN::Client but I'm running into an issue that I haven't been able to figure out. First off, here's some code. Note that I've obviously removed the correct URL/user/pass information so it will be hard to check this code unless you have SVN::Client and a repo to play with.
#! /usr/intel/pkgs/perl/5.12.2/bin/perl use strict; use warnings; package Sub; use SVN::Client; our @ISA = ('SVN::Client'); sub ls { my $self = shift; print "Sub ls function called with arguments:\n".join("\n", @_)."\ +n"; $self->SUPER::ls(@_); } package main; use Data::Dumper; my $obj = Sub->new( auth => [ SVN::Client::get_simple_provider(), SVN::Client::get_ssl_server_trust_file_provider(), SVN::Client::get_simple_prompt_provider( sub {&_set_credential +s(@_)}, 2 ) ] ); my @args = ( 'https://svn.repo.url', 'HEAD', 1 ); print "Calling main ls with arguments:\n".join("\n", @args)."\n\n"; my $ref = $obj->ls(@args); print STDERR Dumper($ref); ###################################################################### +####### sub _set_credentials { my $cred = shift; $cred->username( 'username' ); $cred->password( 'password' ); }
The problem I'm having is with the ls wrapper function in sub. Run as is here (with valid url/user/pass, of course) I get the following output:
plxc16479> $h2/scripts/super_test.pl Calling main ls with arguments: https://svn.repo.url HEAD 1 Sub ls function called with arguments: https://svn.repo.url HEAD 1 TypeError in method 'svn_client_ls', argument 2 of type 'char const *'
However, if instead of instantiating my subclass I change the Sub->new call to SVN::Client->new, I get this:
plxc16479> $h2/scripts/super_test.pl Calling main ls with arguments: https://svn.repo.url HEAD 1 $VAR1 = { 'revision' => bless( do{\(my $o = 10904232)}, '_p_svn_dirent +_t' ), 'all.plist' => bless( do{\(my $o = 10904112)}, '_p_svn_diren +t_t' ) };
Now it works. This tells me that the arguments to the function are good since they're identical in both the direct SVN::Client::ls call and the Sub::ls wrapper function. The question is what's happening in the subclass wrapper function. I've verified the arguments are indeed being passed as expected, identical to the arguments to the direct SVN::Client->ls call
I have put a lot of time into trying to solve this, but no luck as of yet. Am I somehow subclassing this wrong? Am I making the call via SUPER incorrectly somehow? My simple subclass and SUPER tests seem to work, indicating my syntax and methodology here seems to be correct. In any case, I genuinely appreciate any help you kind folks might give.
EDIT: Here's something interesting. If I change the Sub::ls function like so:
sub ls { my $self = shift; print "Sub ls function called with arguments:\n".join("\n", @_)."\ +n"; bless $self, 'SVN::Client'; $self->SUPER::ls(@_); }
It now works as expected. Exact same arguments and call, but it now works with the object being of the SVN::Client class instead of the Sub class. Calling $self->SUPER::ls from the Sub package should call the SVN::Client::ls function regardless of the class of the invocant (right?). Why is the class of the invocant affecting the results of the call here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SVN::Client subclassing issue
by tj_thompson (Monk) on Sep 27, 2011 at 19:33 UTC | |
by Anonymous Monk on Sep 27, 2011 at 19:42 UTC | |
by tj_thompson (Monk) on Sep 27, 2011 at 19:54 UTC | |
by tye (Sage) on Sep 27, 2011 at 20:20 UTC | |
by Anonymous Monk on Sep 27, 2011 at 20:21 UTC | |
|
Re: SVN::Client subclassing issue
by tj_thompson (Monk) on Sep 27, 2011 at 20:38 UTC |