in reply to Re^4: Use method/function signatures with Perl
in thread Use method/function signatures with Perl
sub foo (ARRAY $arr) { ... }
And, I have a class Bar. Today, it is defined as
package Bar; sub new { bless [], shift }
This means that
my $bar = Bar->new; foo( $bar );
will work just fine. But, what happens if the implementation of Bar changes from arrayref to hashref? This is a completely internal change, but one that will break the code listed above.
Personally, I would define it to be
if ($signature) { if (blessed $x) { return TRUE if $x->isa( $signature ); } elsif (ref $x) { return TRUE if ref $x eq $signature; } else { die "$x doesn't match $signature\n"; } }
In other words, if it's been blessed, you only consider the class - not the underlying implementation.
Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Use method/function signatures with Perl
by Ovid (Cardinal) on Dec 06, 2004 at 16:35 UTC | |
by dragonchild (Archbishop) on Dec 06, 2004 at 16:40 UTC |