use warnings;
use Test::More;
-use Test::Exception;
+use Test::Fatal;
use Class::MOP;
{
- package My::Meta::Package;
-
+ package My::Package::Stash;
use strict;
use warnings;
- use Carp 'confess';
- use Symbol 'gensym';
+ use base 'Package::Stash';
- use base 'Class::MOP::Package';
+ use metaclass;
+
+ use Symbol 'gensym';
__PACKAGE__->meta->add_attribute(
'namespace' => (
)
);
+ sub new {
+ my $class = shift;
+ $class->meta->new_object(__INSTANCE__ => $class->SUPER::new(@_));
+ }
+
sub add_package_symbol {
my ($self, $variable, $initial_value) = @_;
}
}
+{
+ 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 :)
my $meta = My::Meta::Package->initialize('Foo');
ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet');
ok(!$meta->has_package_symbol('%foo'), '... the meta agrees');
-lives_ok {
+is( exception {
$meta->add_package_symbol('%foo' => { one => 1 });
-} '... the %foo symbol is created succcessfully';
+}, undef, '... the %foo symbol is created succcessfully' );
ok(!defined($Foo::{foo}), '... the %foo slot has not been created in the actual Foo package');
ok($meta->has_package_symbol('%foo'), '... the meta agrees');
ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet');
-lives_ok {
+is( exception {
$meta->add_package_symbol('@bar' => [ 1, 2, 3 ]);
-} '... created @Foo::bar successfully';
+}, undef, '... created @Foo::bar successfully' );
ok(!defined($Foo::{bar}), '... the @bar slot has still not been created');
ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet');
-lives_ok {
+is( exception {
$meta->add_package_symbol('%baz');
-} '... created %Foo::baz successfully';
+}, undef, '... created %Foo::baz successfully' );
ok(!defined($Foo::{baz}), '... the %baz slot has still not been created');