Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Stevie-O's scratchpad

by Stevie-O (Friar)
on Jun 01, 2004 at 23:41 UTC ( #358828=scratchpad: print w/ replies, xml ) Need Help??

#!/usr/bin/perl -l # once again, symbol table hacking saves the day # (or is that 'destroys the day'?) { package UNIVERSAL; BEGIN { $old_can = \&{'can'}; # a very bizarre effect occurrs if you do this #undef &{'can'}; *{'can'} = \&hacked_can; } } require Scalar::Util; { package Foo; sub new { bless {} } sub can { print "{Foo::can called}"; sub { } } } { package Bar; sub new { bless {} } sub ooh { } } { package UNIVERSAL; sub hacked_can { # detect recursion from ourselves if ((caller(2))[3] =~ /hacked_can$/) { # print 'recursion detected'; goto $old_can; } return undef unless Scalar::Util::blessed($_[0]); return $_[0]->can($_[1]); } } $x = new Foo; $y = new Bar; print '$x can ooh? ', 0+!!UNIVERSAL::can($x, 'ooh'); print '$y can ooh? ', 0+!!UNIVERSAL::can($y, 'ooh'); print '$x can ahh? ', 0+!!UNIVERSAL::can($x, 'ahh'); print '$y can ahh? ', 0+!!UNIVERSAL::can($y, 'ahh');
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2015-07-28 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls