use Carp 'confess';
use Scalar::Util 'blessed';
+sub import {
+ shift;
+
+ my $policy = shift || return;
+
+ unless (Moose::_is_class_already_loaded($policy)) {
+ ($policy->require) or confess "Could not load policy module " .
+ "'$policy' because : $UNIVERSAL::require::ERROR";
+ }
+
+ my $package = caller();
+ $package->can('meta') and
+ croak("'$package' already has a meta() method");
+
+ my $metaclass = 'Moose::Meta::Class';
+ $metaclass = $policy->metaclass($package)
+ if $policy->can('metaclass');
+
+ my %options;
+
+ # build options out of policy's constants
+ $policy->can($_) and $options{":$_"} = $policy->$_($package)
+ for (qw(
+ attribute_metaclass
+ instance_metaclass
+ method_metaclass
+ ));
+
+ # 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__
+
+=pod
+
=head1 NAME
Moose::Policy - moose-mounted police
=head1 SYNOPSIS
-This class allows you to specify your project-wide or company-wide Moose
-meta policy in one location.
-
package Foo;
use Moose::Policy 'My::MooseBestPractice';
has 'bar' => (is => 'rw', default => 'Foo::bar');
has 'baz' => (is => 'ro', default => 'Foo::baz');
-=head1 USAGE
+=head1 DESCRIPTION
- use Moose::Policy 'My::Policy';
- use Moose;
- ...
- no Moose;
+This class allows you to specify your project-wide or company-wide Moose
+meta policy in one location.
-=over
+=head1 CAVEAT
+
+=over 4
=item YOU MUST
return('Our::Attributes');
}
-=head1 AUTHOR
-
-Stevan Little E<lt>stevan@iinteractive.comE<gt>
-
-In response to a feature request by Eric Wilhelm and suggestions by Matt
-Trout.
-
-Documentation and some code are Eric's fault.
-
-=head1 COPYRIGHT AND LICENSE
-
-...
-
=head1 SEE ALSO
L<Moose>, L<Moose::Meta::Class>
-=cut
+=head1 BUGS
-sub import {
- shift;
-
- my $policy = shift || return;
-
- unless (Moose::_is_class_already_loaded($policy)) {
- ($policy->require) or confess "Could not load policy module " .
- "'$policy' because : $UNIVERSAL::require::ERROR";
- }
+All complex software has bugs lurking in it, and this module is no
+exception. If you find a bug please either email me, or add the bug
+to cpan-RT.
- my $package = caller();
- $package->can('meta') and
- croak("'$package' already has a meta() method");
+=head1 AUTHOR
- my $metaclass = 'Moose::Meta::Class';
- $metaclass = $policy->metaclass($package)
- if $policy->can('metaclass');
+Stevan Little E<lt>stevan@iinteractive.comE<gt>
- my %options;
+Eric Wilhelm E<lt>...E<gt>
- # build options out of policy's constants
- $policy->can($_) and $options{":$_"} = $policy->$_($package)
- for (qw(
- attribute_metaclass
- instance_metaclass
- method_metaclass
- ));
+=head1 COPYRIGHT AND LICENSE
- # 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)
- });
-}
+Copyright 2006 by Infinity Interactive, Inc.
-1;
+L<http://www.iinteractive.com>
-__END__
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+=cut