Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Subs calling themselves

by roboticus (Chancellor)
on May 07, 2021 at 13:05 UTC ( [id://11132216]=note: print w/replies, xml ) Need Help??


in reply to Subs calling themselves

Bod:

The second function, access_token, is fetching a value from the object referenced by $self, so it's pretty straightforward.

The request function is a *little* more subtle: As you notice, it calls the access_token function, but the result from that call is treated as a reference to an object that has a request function. Note that the object referenced by access_token is *not* necessarily the same class or object found in the request function you posted. So in order to understand what's happening, you'll need to figure out where the access_token member in the object is being set, so you can figure out what sort of object is being accessed.

Sometimes when tracking through the code is a bit annoying, I'll do something like a quick edit of the module:

$ # make a copy of the module so I don't mess it up $ cp /home/shoples1/perl5/lib/perl5/LWP/Authen/OAuth2.pm foo.pm $ vi /home/shoples1/perl5/lib/perl5/LWP/Authen/OAuth2.pm . . . edit the request subroutine to look like: sub request { my ($self, $request, @rest) = @_; use Data::Dumper; my $temp = $self->access_token; print "access token is: ", Dumper($temp), "\n"; return $temp->request($self, $request, @rest); } $ # run the project so I can see what I'm looking for $ perl t.pl blah, blah, blah access token is:$VAR1 = bless( { 'baz' => 'boom', 'foo' => 'bar' }, 'Barsoom!' ); blah, blah, blah $ # put things back so I don't cause more problems for myself $ cp foo.pm /home/shoples1/perl5/lib/perl5/LWP/Authen/OAuth2.pm

Hope this helps!

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: Subs calling themselves
by Bod (Parson) on May 07, 2021 at 21:43 UTC
    Hope this helps!

    Yes...it helps a lot. Thank you

    I need to work out why $self->access_token ends up being undefined and having a way to peek inside the module has to be helpful in working that out.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-19 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found