From: stevan Date: Sat, 5 Aug 2006 21:41:38 +0000 (+0000) Subject: broken-test X-Git-Tag: 0_01~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMoose-Policy.git;a=commitdiff_plain;h=b9238462c9d0e46830c5bd0ce94771826c1079a4 broken-test --- diff --git a/lib/Moose/Policy.pm b/lib/Moose/Policy.pm index ee4a660..ffe4b69 100644 --- a/lib/Moose/Policy.pm +++ b/lib/Moose/Policy.pm @@ -4,6 +4,44 @@ package Moose::Policy; use strict; use warnings; +our $VERSION = '0.01'; + +use Moose (); +use Carp 'confess'; +use Scalar::Util 'blessed'; + +sub import { + shift; + + my $policy = shift || return; + + unless (Moose::_is_class_already_loaded($policy)) { + ($policy->require) + || confess "Could not load policy module '$policy' because : " . $UNIVERSAL::require::ERROR; + } + + my $metaclass = 'Moose::Meta::Class'; + $metaclass = $policy->metaclass if $policy->can('metaclass'); + + my %options; + + $options{':attribute_metaclass'} = $policy->attribute_metaclass + if $policy->can('attribute_metaclass'); + + my $package = caller(); + + # create a meta object so we can install &meta + my $meta = $metaclass->initialize($package => %options); + $meta->add_method('meta' => sub { + # we must re-initialize so that it + # works as expected in subclasses, + # since metaclass instances are + # singletons, this is not really a + # big deal anyway. + $metaclass->initialize((blessed($_[0]) || $_[0]) => %options) + }); +} + 1; __END__ diff --git a/t/001_basic.t b/t/001_basic.t index 549a5c6..3133f4a 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -15,7 +15,7 @@ BEGIN { extends 'Moose::Meta::Attribute'; - before '_process_options' => sub { + sub _process_options { my ($class, $name, $options) = @_; if (exists $options->{is}) { if ($options->{is} eq 'ro') { @@ -27,10 +27,11 @@ BEGIN { } delete $options->{is}; } - }; + + $class->SUPER::_process_options($name, $options); + } } - { package My::Moose::Policy; use constant attribute_metaclass => 'My::Moose::Meta::Attribute'; @@ -45,6 +46,10 @@ BEGIN { has 'bar' => (default => 'Foo::bar'); } +isa_ok(Foo->meta, 'Moose::Meta::Class'); +is(Foo->meta->attribute_metaclass, 'My::Moose::Meta::Attribute', '... got our custom attr metaclass'); + +isa_ok() my $foo = Foo->new; isa_ok($foo, 'Foo');