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?


In reply to SVN::Client subclassing issue by tj_thompson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.