So I'm stepping through some code in a cpan module ...

I have undef for @_, so I'm expecting to execute line 148 next. However, the debugger puts me on line 145. Why did it go to 145 instead of 148? Why would undef be treated as a true value?

DB<13> n Net::DBus::RemoteService::get_object(/usr/lib/perl5/Net/DBus/RemoteSer +vice.pm:144): 144: if (@_) { DB<13> l 144==> if (@_) { 145: my $interface = shift; 146: return $self->{objects}->{$object_path}->as_interface($int +erface); 147 } else { 148: return $self->{objects}->{$object_path}; 149 } 150 } 151 152: 1; 153 DB<13> x @_ 0 undef DB<14> n Net::DBus::RemoteService::get_object(/usr/lib/perl5/Net/DBus/RemoteSer +vice.pm:145): 145: my $interface = shift; DB<14> n Net::DBus::RemoteService::get_object(/usr/lib/perl5/Net/DBus/RemoteSer +vice.pm:146): 146: return $self->{objects}->{$object_path}->as_interface($int +erface); DB<14> x $interface 0 undef

The method was invoked as $proxy = $service->get_object($self->{object_path}, $mdata->{interface}); and the innards of the function have shifted the parameters into variables. So @_ should have 0 elements, right?

Here is the whole method from /usr/lib/perl5/Net/DBus/RemoteService.pm
135 sub get_object { 136: my $self = shift; 137: my $object_path = shift; 138 139: unless (defined $self->{objects}->{$object_path}) { 140: $self->{objects}->{$object_path} = Net::DBus::RemoteObject +->new($self, 141 $object_path); 142 } 143 144: if (@_) { 145: my $interface = shift; 146==> return $self->{objects}->{$object_path}->as_interface($i +nterface); 147 } else { 148: return $self->{objects}->{$object_path}; 149 } 150 }
Update: I just realized that the 1st parameter is the added class object. DUH :-( So it's a three element array. Back to this in a few after I rerun the debugger.

In reply to Two element array, shifted twice, is true? by SwaJime

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.