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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.