Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^6: Reference assessment techniques and how they fail (run?)

by kyle (Abbot)
on Feb 18, 2008 at 04:27 UTC ( [id://668472]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Reference assessment techniques and how they fail (run?)
in thread Reference assessment techniques and how they fail

When I tested eval, it did invoke overload methods. Here's the test (see also Re^4: Reference assessment techniques and how they fail for a longer version for code refs):

use strict; use warnings; use Test::More 'tests' => 4; use Scalar::Util qw( blessed reftype ); my $side_effect = 0; package OverloadHash; use overload '%{}' => sub { $side_effect = 1; {} }; package main; sub is_hash_eval { no warnings qw( void uninitialized ); return '' ne ref $_[0] && eval { %{$_[0]}; 1 }; } sub is_hash_util { my $suspected_hash = shift; return 0 if '' eq ref $suspected_hash; return 1 if 'HASH' eq reftype $suspected_hash; if ( blessed $suspected_hash && overload::Method( $suspected_hash, '%{}' ) ) { return 1; } return 0; } check_method( \&is_hash_util, 'utils' ); check_method( \&is_hash_eval, 'eval' ); sub check_method { my ( $tester, $name ) = @_; $side_effect = 0; my $overhash = bless {}, 'OverloadHash'; ok( $tester->( $overhash ), "$name: overloaded reference" ); # this test fails for the eval method ok( ! $side_effect, "$name: no side effect" ); }

I agree that the best solution to all this would be something sweet in Scalar::Util. I trust it to stay up to date, and it's the right place for it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://668472]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found