Created
January 30, 2012 09:09
-
-
Save motemen/1703474 to your computer and use it in GitHub Desktop.
UNIVERSAL::the
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use PadWalker qw(peek_my); | |
use Scalar::Util qw(blessed); | |
use Class::Load qw(is_class_loaded); | |
sub UNIVERSAL::the { | |
my $class = shift; | |
my $vars = peek_my(1); | |
my @the = grep { blessed $_ && is_class_loaded($class) ? $_->isa($class) : ref $_ eq $class } map { $$_ } values %$vars; | |
wantarray ? @the : $the[0]; | |
} | |
{ | |
package Foo; | |
use Mouse; | |
} | |
use Test::More tests => 8; | |
for my $a (Foo->new, Foo->new) { | |
for my $b ({ i => 0 }, { i => 1 }) { | |
is the Foo, $a; | |
is the HASH, $b; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment