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?