in reply to Re: eval-blocks and Test::Builder
in thread eval-blocks and Test::Builder
(Your version misses the fact that 'ARRAY' is a legal classname and that the value returned from tied() is a blessed hashref which makes the _get_self() for DBM::Deep::Hash more complex.)sub _get_self { my $reftype = Scalar::Util::reftype( $_[0] ); $reftype = '' unless defined $reftype; if ( $reftype eq 'ARRAY' ) { return tied( @{ $_[0] } || $_[0] } return $_[0]; }
(Yes, my code could be shortened if I was able to use // for defined-or. That's a 5.10ism and DBM::Deep runs on practically every Perl version since 5.004, we think.)
I don't like that code for three reasons:
By using an eval-block, you allow the item to behave the way it wants to behave, if it wants to behave that way, plus you let Perl worry about the edgecases. To get truly equivalent code would be about 40 lines and I don't think I could get it all correct. At that point, an eval-block is quicker.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: eval-blocks and Test::Builder
by fergal (Chaplain) on Feb 25, 2006 at 01:16 UTC | |
by dragonchild (Archbishop) on Feb 25, 2006 at 03:07 UTC | |
by fergal (Chaplain) on Feb 25, 2006 at 12:35 UTC | |
by Aristotle (Chancellor) on Mar 01, 2006 at 16:03 UTC |