What are you hoping to get out of ref() and what is it giving you now when you feed it your faker-objects?

Incidentally, if Scalar::Util's blessed() is available, $result = blessed($maybe_obj) and $maybe_obj->isa( ... ); might be faster than eval { $result->isa( ... ) };.

Rate eval2 blessed1 eval1 blessed2 eval2 6.80/s -- -57% -61% -76% blessed1 15.9/s 134% -- -9% -43% eval1 17.4/s 156% 10% -- -38% blessed2 28.0/s 313% 76% 61% --

Here's the test script:

#!/usr/bin/perl use strict; use warnings; use Scalar::Util qw( blessed ); use Benchmark qw( cmpthese ); my $obj = bless {}, 'Foo'; my $not_obj; my $result; cmpthese( -1, { eval1 => sub { for ( 0 .. 10_000 ) { $result = eval { $obj->isa('Foo') }; $result = eval { $obj->isa('Bar') }; } }, blessed1 => sub { for ( 0 .. 10_000 ) { $result = blessed($obj) and $obj->isa('Foo'); $result = blessed($obj) and $obj->isa('Bar'); } }, eval2 => sub { for ( 0 .. 10_000 ) { $result = eval { $not_obj->isa('Foo') }; $result = eval { $not_obj->isa('Bar') }; } }, blessed2 => sub { for ( 0 .. 10_000 ) { $result = blessed($not_obj) and $not_obj->isa('Foo'); $result = blessed($not_obj) and $not_obj->isa('Bar'); } }, });
--
Marvin Humphrey
Rectangular Research ― http://www.rectangular.com

In reply to Re: Overloading ref() just like ->isa and ->can? by creamygoodness
in thread Overloading ref() just like ->isa and ->can? by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.