From: Jesse Luehrs Date: Mon, 27 Sep 2010 09:17:19 +0000 (-0500) Subject: tests for meta_name X-Git-Tag: 1.15~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1c3304e69c45c743834802830f7a460a68654678;p=gitmo%2FMoose.git tests for meta_name --- diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index 57d5a55..e4e012f 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -426,7 +426,7 @@ sub _make_import_sub { } sub _strip_traits { - my $idx = first_index { $_ eq '-traits' } @_; + my $idx = first_index { ( $_ || '' ) eq '-traits' } @_; return ( [], @_ ) unless $idx >= 0 && $#_ >= $idx + 1; @@ -440,7 +440,7 @@ sub _strip_traits { } sub _strip_metaclass { - my $idx = first_index { $_ eq '-metaclass' } @_; + my $idx = first_index { ( $_ || '' ) eq '-metaclass' } @_; return ( undef, @_ ) unless $idx >= 0 && $#_ >= $idx + 1; @@ -452,7 +452,7 @@ sub _strip_metaclass { } sub _strip_meta_name { - my $idx = first_index { $_ eq '-meta_name' } @_; + my $idx = first_index { ( $_ || '' ) eq '-meta_name' } @_; return ( 'meta', @_ ) unless $idx >= 0 && $#_ >= $idx + 1; diff --git a/t/050_metaclasses/062_meta_name.t b/t/050_metaclasses/062_meta_name.t new file mode 100644 index 0000000..db3d9ac --- /dev/null +++ b/t/050_metaclasses/062_meta_name.t @@ -0,0 +1,43 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + # so we don't pick up stuff from Moose::Object + package Base; + sub foo { } # touch it so that 'extends' doesn't try to load it +} + +{ + package Foo; + use Moose; + extends 'Base'; + no Moose; +} +can_ok('Foo', 'meta'); +is(Foo->meta, Class::MOP::class_of('Foo')); +isa_ok(Foo->meta->get_method('meta'), 'Moose::Meta::Method::Meta'); + +{ + package Bar; + use Moose -meta_name => 'bar_meta'; + extends 'Base'; + no Moose; +} +ok(!Bar->can('meta')); +can_ok('Bar', 'bar_meta'); +is(Bar->bar_meta, Class::MOP::class_of('Bar')); +isa_ok(Bar->bar_meta->get_method('bar_meta'), 'Moose::Meta::Method::Meta'); + +{ + package Baz; + use Moose -meta_name => undef; + extends 'Base'; + no Moose; +} +ok(!Baz->can('meta')); +# 1 because of the dummy method we installed in Base +is(scalar Class::MOP::class_of('Baz')->get_all_methods, 1); + +done_testing;