broken-test
[gitmo/Moose-Policy.git] / lib / Moose / Policy.pm
CommitLineData
82cfc049 1
2package Moose::Policy;
3
4use strict;
5use warnings;
6
b9238462 7our $VERSION = '0.01';
8
9use Moose ();
10use Carp 'confess';
11use Scalar::Util 'blessed';
12
13sub import {
14 shift;
15
16 my $policy = shift || return;
17
18 unless (Moose::_is_class_already_loaded($policy)) {
19 ($policy->require)
20 || confess "Could not load policy module '$policy' because : " . $UNIVERSAL::require::ERROR;
21 }
22
23 my $metaclass = 'Moose::Meta::Class';
24 $metaclass = $policy->metaclass if $policy->can('metaclass');
25
26 my %options;
27
28 $options{':attribute_metaclass'} = $policy->attribute_metaclass
29 if $policy->can('attribute_metaclass');
30
31 my $package = caller();
32
33 # create a meta object so we can install &meta
34 my $meta = $metaclass->initialize($package => %options);
35 $meta->add_method('meta' => sub {
36 # we must re-initialize so that it
37 # works as expected in subclasses,
38 # since metaclass instances are
39 # singletons, this is not really a
40 # big deal anyway.
41 $metaclass->initialize((blessed($_[0]) || $_[0]) => %options)
42 });
43}
44
82cfc049 451;
46
47__END__
48