[Moose-commits] r7247 - in Class-MOP/branches/meta-independence:
lib/Class t
sartak at code2.0beta.co.uk
sartak at code2.0beta.co.uk
Wed Jan 7 14:24:28 GMT 2009
Author: sartak
Date: 2009-01-07 06:24:28 -0800 (Wed, 07 Jan 2009)
New Revision: 7247
Added:
Class-MOP/branches/meta-independence/t/084_get_meta.t
Modified:
Class-MOP/branches/meta-independence/lib/Class/MOP.pm
Log:
Implement get_meta, begin writing tests for it
Modified: Class-MOP/branches/meta-independence/lib/Class/MOP.pm
===================================================================
--- Class-MOP/branches/meta-independence/lib/Class/MOP.pm 2009-01-07 14:21:06 UTC (rev 7246)
+++ Class-MOP/branches/meta-independence/lib/Class/MOP.pm 2009-01-07 14:24:28 UTC (rev 7247)
@@ -9,7 +9,7 @@
use MRO::Compat;
use Carp 'confess';
-use Scalar::Util 'weaken';
+use Scalar::Util qw/weaken blessed/;
use Class::MOP::Class;
@@ -64,7 +64,7 @@
die $e if $e && $e !~ /object version|loadable object/;
return $e ? 0 : 1;
-}
+ }
sub _load_pure_perl {
require Sub::Identify;
@@ -93,6 +93,8 @@
sub does_metaclass_exist { exists $METAS{$_[0]} && defined $METAS{$_[0]} }
sub remove_metaclass_by_name { $METAS{$_[0]} = undef }
+ sub get_meta { $METAS{ blessed($_[0]) || $_[0] } }
+
# NOTE:
# We only cache metaclasses, meaning instances of
# Class::MOP::Class. We do not cache instance of
Added: Class-MOP/branches/meta-independence/t/084_get_meta.t
===================================================================
--- Class-MOP/branches/meta-independence/t/084_get_meta.t (rev 0)
+++ Class-MOP/branches/meta-independence/t/084_get_meta.t 2009-01-07 14:24:28 UTC (rev 7247)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use Test::More tests => 4;
+
+require Class::MOP;
+
+is(Class::MOP::get_meta('Does::Not::Exist'), undef, "... get_meta on a nonexistent class returns undef");
+is(Class::MOP::get_meta(bless {}, 'Does::Not::Exist'), undef, "... get_meta on an instance of a nonexistent class returns undef");
+
+is(Class::MOP::get_meta('Class::MOP::Class'), Class::MOP::Class->meta, "... get_meta on Class::MOP::Class returns its metaclass");
+is(Class::MOP::get_meta(bless {}, 'Class::MOP::Class'), Class::MOP::Class->meta, "... get_meta on an instance of Class::MOP::Class returns its metaclass");
+
More information about the Moose-commits
mailing list