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__