Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday January 08, 2009
10:56 AM


[ #38239 ]

While digging around in the debugger, I came across a method on a an object that I wasn't expecting to see. So I ack'd for it.

$ ack -a 'a_sub_not_likely_to_be_here' deps
20:     eval 'sub UNIVERSAL::a_sub_not_likely_to_be_here { ref($_[0]) }';
24:             ? eval { $_[0]->a_sub_not_likely_to_be_here }

1285:        eval 'sub UNIVERSAL::a_sub_not_likely_to_be_here { ref($_[0]) }';
1288:            ref($_[0]) ? eval { $_[0]->a_sub_not_likely_to_be_here } : undef;

14:                *UNIVERSAL::a_sub_not_likely_to_be_here = sub {
30:                        ? eval { $_[0]->a_sub_not_likely_to_be_here }
53:                eval { $r->a_sub_not_likely_to_be_here; 1 }

32:                *UNIVERSAL::a_sub_not_likely_to_be_here = sub {
48:                        ? eval { $_[0]->a_sub_not_likely_to_be_here }
71:                eval { $r->a_sub_not_likely_to_be_here; 1 }

Why do four different modules do this?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Mouse (and thus Mouse::Tiny, which is a one-file concatenation of the Mouse libraries) use this because Scalar::Util's pure-perl version does, to emulate Scalar::Util::blessed without XS.

    More recent versions of Mouse have removed this bit of code, deciding that (at least for now), if you want 5.6 you get a dependency on Scalar::Util.

  • I've got a bloody good mind to write Break::Mouse which will delete that subroutine if it ever spots that it's been created. And load it into my CPAN-testing machines.

    This shows why monkey-patching is generally a bad idea.

    package Break::Mouse;

    use Time::HiRes qw(setitimer ITIMER_VIRTUAL);
    setitimer(ITIMER_VIRTUAL, 1, 1);
    $SIG{VTALRM} = sub {
        eval 'sub UNIVERSAL::a_sub_not_likely_to_be_here { die("Monkey-patching is bad\n")';

    • Evil indeed.

      So how do we implement blessed without XS? As I said in a sibling comment, Mouse doesn't do this any more, it now just depends on Scalar::Util. But since I just took the code from Scalar::Util, so your package should be named Break::Scalar::Util.

      • Check to see if it's a reference and *isn't* a reference to a scalar/array/hash/sub etc. The list of magic values returned by ref() for all the built-in types is in perldoc -f ref.

        • Seems silly to reinvent the wheel when Scalar::Util already has a nice shiny round one in the core.
      • UNIVERSAL::can( $foo, 'can' )

    • Wow, thats a loooong way to go to prove a point! (especially since the point it no longer valid (see Sartak's response below)).

      Not to mention the fact that it is a generally bad idea since it will break Scalar::Util (and Mouse too) which is a core module, therefore resulting in a whole lot of false negatives from your CPAN testing machines.

      While I normally agree with you that monkeypatching is an evil practice, like all evil practices there are some exceptions. In this case what Sartak was doing in Mou

      • Please return your humour-detector to the shop for a repacement. It is faulty.
        • I don't find threats funny, ... and neither does the Dept. of Homeland Security!!!

          YOU ARE NOW ON THE WATCH LIST!!!!!!!! :P

      • In this case what Sartak was doing in Mouse was for the greater good (making it possible to use the Moose/Mouse goodness in a zero-dependency fashion)....

        Alternately, you could target only sane and modern versions of Perl, in the theory that anyone knowledgeable enough to use Mouse or Moose should be able to rely on a Perl version released this millennium.