[Moose-commits] r7818 - in Mouse/trunk: lib t t/lib
tokuhirom at code2.0beta.co.uk
tokuhirom at code2.0beta.co.uk
Wed Mar 4 22:26:34 GMT 2009
Author: tokuhirom
Date: 2009-03-04 14:26:34 -0800 (Wed, 04 Mar 2009)
New Revision: 7818
Added:
Mouse/trunk/t/045-import-into_level.t
Mouse/trunk/t/lib/BaseClass.pm
Modified:
Mouse/trunk/lib/Mouse.pm
Log:
support Mouse->import({into_level => 1}).
This feature is needed by any::moose based hacky classes(e.g. http::engine::middleware)
Modified: Mouse/trunk/lib/Mouse.pm
===================================================================
--- Mouse/trunk/lib/Mouse.pm 2009-03-04 22:26:21 UTC (rev 7817)
+++ Mouse/trunk/lib/Mouse.pm 2009-03-04 22:26:34 UTC (rev 7818)
@@ -125,7 +125,16 @@
strict->import;
warnings->import;
- my $caller = caller;
+ my $opts = do {
+ if (ref($_[0]) && ref($_[0]) eq 'HASH') {
+ shift @_;
+ } else {
+ +{ };
+ }
+ };
+ my $level = delete $opts->{into_level};
+ $level = 0 unless defined $level;
+ my $caller = caller($level);
# we should never export to main
if ($caller eq 'main') {
@@ -142,7 +151,7 @@
*{$caller.'::meta'} = sub { $meta };
if (@_) {
- __PACKAGE__->export_to_level( 1, $class, @_);
+ __PACKAGE__->export_to_level( $level+1, $class, @_);
} else {
# shortcut for the common case of no type character
no strict 'refs';
Added: Mouse/trunk/t/045-import-into_level.t
===================================================================
--- Mouse/trunk/t/045-import-into_level.t (rev 0)
+++ Mouse/trunk/t/045-import-into_level.t 2009-03-04 22:26:34 UTC (rev 7818)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More tests => 1;
+
+{
+ package Foo;
+ use BaseClass;
+}
+
+is(Foo->new->foo(), 'bar');
+
Added: Mouse/trunk/t/lib/BaseClass.pm
===================================================================
--- Mouse/trunk/t/lib/BaseClass.pm (rev 0)
+++ Mouse/trunk/t/lib/BaseClass.pm 2009-03-04 22:26:34 UTC (rev 7818)
@@ -0,0 +1,10 @@
+package BaseClass;
+use Mouse;
+
+sub import {
+ my $pkg = caller(0);
+ Mouse->import({into_level => 1});
+ $pkg->meta->add_method('foo' => sub {'bar'});
+}
+
+1;
More information about the Moose-commits
mailing list