From: Jesse Luehrs Date: Tue, 6 Jul 2010 05:50:15 +0000 (-0500) Subject: allow not importing a meta method X-Git-Tag: 1.09~43 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cdf923f85e2cdc4c5adcc1efbb05d4bcf2241b24;p=gitmo%2FClass-MOP.git allow not importing a meta method --- diff --git a/lib/metaclass.pm b/lib/metaclass.pm index 1eca64d..f165b86 100644 --- a/lib/metaclass.pm +++ b/lib/metaclass.pm @@ -41,6 +41,7 @@ sub import { # create a meta object so we can install &meta my $meta = $metaclass->initialize($package => %options); + my $should_install = !delete $options{no_meta}; $meta->add_method('meta' => sub { # we must re-initialize so that it # works as expected in subclasses, @@ -48,7 +49,7 @@ sub import { # singletons, this is not really a # big deal anyway. $metaclass->initialize((blessed($_[0]) || $_[0]) => %options) - }); + }) if $should_install; } 1; diff --git a/t/090_no_meta_method.t b/t/090_no_meta_method.t new file mode 100644 index 0000000..a28c027 --- /dev/null +++ b/t/090_no_meta_method.t @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Exception; +use Class::MOP; + +{ + package Foo; + use metaclass no_meta => 1; +} + +my $meta = Class::MOP::class_of('Foo'); +ok(!$meta->has_method('meta'), "no meta method was installed"); +$meta->add_method(meta => sub { die 'META' }); +lives_ok { $meta->find_method_by_name('meta') } "can do meta-level stuff"; +lives_ok { $meta->make_immutable } "can do meta-level stuff"; +lives_ok { $meta->class_precedence_list } "can do meta-level stuff"; + +done_testing;