11 use Scalar::Util 'blessed';
16 my $policy = shift || return;
18 unless (Moose::_is_class_already_loaded($policy)) {
20 || confess "Could not load policy module '$policy' because : " . $UNIVERSAL::require::ERROR;
23 my $metaclass = 'Moose::Meta::Class';
24 $metaclass = $policy->metaclass if $policy->can('metaclass');
28 # build options out of policy's constants
29 $policy->can($_) and $options{":$_"} = $policy->$_()
36 my $package = caller();
37 $package->can('meta') and
38 croak("'$package' already has a meta() method");
40 # create a meta object so we can install &meta
41 my $meta = $metaclass->initialize($package => %options);
42 $meta->add_method('meta' => sub {
43 # we must re-initialize so that it
44 # works as expected in subclasses,
45 # since metaclass instances are
46 # singletons, this is not really a
48 $metaclass->initialize((blessed($_[0]) || $_[0]) => %options)