Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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

by tye (Sage)
on Feb 18, 2008 at 04:02 UTC ( #668471=note: print w/replies, xml ) Need Help??

in reply to Re^4: Reference assessment techniques and how they fail
in thread Reference assessment techniques and how they fail

Just a quick note that I tested some form of eval-style test and was pleasantly surprised to find that no overloaded tied methods were actually invoked by the test (as I recall). So my preference is an eval-style test that doesn't run any user code. When such is indeed possible, then it wins (or ties) at both criteria. Unfortunately, I don't have the exact check code nor test handy and I won't be likely to dive into the details of that in the immediate future, it appears. But coming up with eval-style tests that won't emit warnings and demonstrating that they don't call user code (or how little user code they call) would be useful results (hopefully from this thread).

When such isn't possible, then I wouldn't want to use your preferred test unless it came rolled up in a core module such as overload (or, next best, Scalar::Util) so that the next time this stuff changes (or a problem is found) the test is likely to get updated. Of course, that still leaves the problem of using it in a backward-compatible way. For the optimists in the crowd, that reduces to just requiring the install of an updated overload module. But getting something a ton better than what Scalar::Util has managed to provide is long overdue and would certainly be welcomed by me. :)

Updated: to note that I was testing tied items, not overloaded.

- tye        

  • Comment on Re^5: Reference assessment techniques and how they fail (run?)

Replies are listed 'Best First'.
Re^6: Reference assessment techniques and how they fail (run?)
by kyle (Abbot) on Feb 18, 2008 at 04:27 UTC

    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.

Re^6: Reference assessment techniques and how they fail (run?)
by kyle (Abbot) on Feb 18, 2008 at 15:56 UTC

    Here's a test for side effects of an eval test on a tied array.

    It seems the reason nothing is called during the test is that it's happening in void context. If I give the array dereference a context in the eval, it has to make a call to the object.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://668471]
choroba likes the story at the end of the node
[choroba]: reminds me of the days at the bank
[Corion]: Lady_Aleena: Hehe ;-D
[Lady_Aleena]: Corion, it was PerlMonks who kept pushing me to get Linux, so now I know some of the commands to use in word play.
[Corion]: Lady_Aleena: :-D
[Lady_Aleena]: Corion, so do you think the gods would be open to taking over Cookies should I disappear for too long a time?
[Corion]: Lady_Aleena: Yes, I think so, but maybe someone else might also take care of the cookies ;)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-04-26 08:34 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (471 votes). Check out past polls.