Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

writing an api wrapper I get a 1 with my return value from method

by gideondsouza (Pilgrim)
on Jan 15, 2013 at 15:06 UTC ( #1013408=perlquestion: print w/ replies, xml ) Need Help??
gideondsouza has asked for the wisdom of the Perl Monks concerning the following question:

So I'm hoping to write a nice wrapper around the StackExchange Api. It's a little learning project. I use module starter and this is my directory:
.
├── Changes
├── MANIFEST
├── Makefile.PL
├── README
├── ignore.txt
├── lib
│   └── Net
│       ├── StackExchange
│       │   ├── V2
│       │   │   └── Answers.pm
│       │   └── V2.pm
│       └── StackExchange.pm
└── t
    ├── 00-load.t
    ├── boilerplate.t
    ├── manifest.t
    ├── pod-coverage.t
    └── pod.t
Three package files. I have the following code in each of the pm files.
################### # Inside StackExchange.pm ################### sub new { return Net::StackExchange::V2->new(); } ################### # Inside V2.pm ################### sub new { my ($class) = @_; my $self = {}; bless $self, $class; return $self; } sub answers { return Net::StackExchange::V2::Answers->new(); } ################### # Inside Answers.pm ################### sub new { my ($class) = @_; my $self = { auth_token => "", }; bless $self, $class; return $self; } sub getAll { print "All Answers"; }
Here is my problem:
######### # UsageTest.pl ######### use lib("some_path_to_module/Net-StackExchange/lib"); use Net::StackExchange; my $a = Net::StackExchange->new(); my $r = $a->answers->getAl(); print $r; # Using Dumper.. print Dumper($r); #returns => All Answers$VAR1 = 1

The output I get is : All Anwers1

I cannot figure out for the life of me where that 1 (one) came from? Is it the one from the package returning 1? Doesn't make any sense to me!!

Comment on writing an api wrapper I get a 1 with my return value from method
Select or Download Code
Re: writing an api wrapper I get a 1 with my return value from method
by kennethk (Monsignor) on Jan 15, 2013 at 15:15 UTC

    The last statement in your getAll routine is print "All Answers";. A subroutine returns without explicit return "automatically returns the value of the last expression evaluated." print "[r]eturns true if successful", so getAll returns 1.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      Ah man! I had a feeling it was something silly :( I'm a little embarrassed

      Oh well, you live and learn!

      Thanks very much for you reply kennethk

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1013408]
Approved by marto
Front-paged by Lotus1
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-07-28 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls