Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: converting libraries into modules

by rvosa (Curate)
on Mar 05, 2006 at 22:43 UTC ( [id://534608]=note: print w/replies, xml ) Need Help??


in reply to Re: converting libraries into modules
in thread converting libraries into modules

I don't think this approach really simplifies things (now you have two interfaces to explain), but if you do it this way I'd suggest you don't hardcode the class name into its methods. I think I'd do:
sub half { my $number; if (ref $_[0] eq __PACKAGE__) { my ( $self, $number ) = @_; } # uncuddles elses are faster! else { $number = $_[0]; } return $number / 2; }
Or even:
sub half { my $number; if (ref $_[0]) { my ( $self, $number ) = @_; } # uncuddles elses are faster! else { $number = $_[0]; } return $number / 2; }
And then, if you're one of those suspenders + belt (just to be safe, you know) kind of people, you can always do looks_like_number $number and throw an exception (with baroque stack trace) on false.

Replies are listed 'Best First'.
Re^3: converting libraries into modules
by blahblah (Friar) on Mar 06, 2006 at 16:05 UTC
    # uncuddles elses are faster!

    What? Is that really true? I thought it was just a style choice...


      No, really, have you tried it with Benchmark?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-19 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found