Skip to content

Instantly share code, notes, and snippets.

@motemen motemen/the.pl
Created Jan 30, 2012

Embed
What would you like to do?
UNIVERSAL::the
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
You can’t perform that action at this time.