X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F081_meta_package_extension.t;h=c8b2735290750cf4450eebde391dcc6e8709ced5;hb=0cf811c0867feb0e846eb3bc1f34aee4a1f169f1;hp=8ede7457fbc170c0bf83ebfbf47312d7602ba1db;hpb=55039f82288984867a24b027addcfe9f2a694217;p=gitmo%2FClass-MOP.git diff --git a/t/081_meta_package_extension.t b/t/081_meta_package_extension.t index 8ede745..c8b2735 100644 --- a/t/081_meta_package_extension.t +++ b/t/081_meta_package_extension.t @@ -1,39 +1,56 @@ use strict; use warnings; -use Test::More tests => 15; +use Test::More; use Test::Exception; -BEGIN {use Class::MOP; -} +use Class::MOP; { - package My::Meta::Package; - + package My::Package::Stash; use strict; use warnings; - - use Carp 'confess'; + + use base 'Package::Stash'; + + use metaclass; + use Symbol 'gensym'; - - use base 'Class::MOP::Package'; - + __PACKAGE__->meta->add_attribute( 'namespace' => ( reader => 'namespace', default => sub { {} } ) - ); - + ); + + sub new { + my $class = shift; + $class->meta->new_object(__INSTANCE__ => $class->SUPER::new(@_)); + } + sub add_package_symbol { my ($self, $variable, $initial_value) = @_; - - my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable); - + + my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable); + my $glob = gensym(); *{$glob} = $initial_value if defined $initial_value; - $self->namespace->{$name} = *{$glob}; - } + $self->namespace->{$name} = *{$glob}; + } +} + +{ + package My::Meta::Package; + + use strict; + use warnings; + + use base 'Class::MOP::Package'; + + sub _package_stash { + $_[0]->{_package_stash} ||= My::Package::Stash->new($_[0]->name); + } } # No actually package Foo exists :) @@ -75,3 +92,4 @@ lives_ok { ok(!defined($Foo::{baz}), '... the %baz slot has still not been created'); +done_testing;