in reply to Re^4: RFC: Perl meta programming
in thread RFC: Perl meta programming
There's some real food for thought in your replies, thanks.
So if get the point, there is no easy way to test whether something can be treated as a hash ref (for instance) short of trying to do so. So the best way to test is to try and catch any exceptions that indicate failure.
If I want to verify membership in a class, I'd need to do something like:
# Option 1. if ( eval { $foo->isa('Some::Class') } ) { # Do stuff with Some::Class } # or Option 2. use Scalar::Util; if ( blessed $foo and $foo->isa('Some::Class') ) { # Do stuff with Some::Class }
Are there any big ugly problems with either option? I've tested both and they seem OK, but there's no point trying to learn a new habbit, if it's a bad one!
TGI says moo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: RFC: Perl meta programming
by diotalevi (Canon) on Oct 22, 2006 at 18:15 UTC | |
by druud (Sexton) on Sep 13, 2009 at 11:20 UTC | |
|
Re^6: RFC: Perl meta programming
by diotalevi (Canon) on Oct 22, 2006 at 18:37 UTC | |
|
Re^6: RFC: Perl meta programming
by chromatic (Archbishop) on Oct 22, 2006 at 21:11 UTC |