in reply to Re^4: Solving the SUPER problem in Mixins with String Eval
in thread Solving the SUPER problem in Mixins with String Eval
sub add_stuff_to_file { my ($filehandle, $stuff) = @_; my $i = $stuff->iterator(); while ($i->hasNext()) { print $filehandle $i->next(); } }
Or if you want similar error messages:
sub add_stuff_to_file { my ($filehandle, $stuff) = @_; ($stuff->can('iterator')) || die "Stuff must be iterable"; my $i = $stuff->iterator(); ($i->can('hasNext') and $i->can('next')) || die "Stuff's iterator must be an Iterator"; while ($i->hasNext()) { print $filehandle $i->next(); } }
What is the upside of checking isa when you're deliberately trying to cast a wide net?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Solving the SUPER problem in Mixins with String Eval
by stvn (Monsignor) on Oct 12, 2004 at 20:36 UTC |