package Moose::Policy;
-# vim:ts=4:sw=4:et:sta
-
use strict;
use warnings;
--- /dev/null
+
+package Moose::Policy::FollowPBP;
+
+use constant attribute_metaclass => 'Moose::Policy::FollowPBP::Attribute';
+
+package Moose::Policy::FollowPBP::Attribute;
+use Moose;
+
+extends 'Moose::Meta::Attribute';
+
+before '_process_options' => sub {
+ my ($class, $name, $options) = @_;
+ # NOTE:
+ # If is has been specified, and
+ # we don't have a reader or writer
+ # Of couse this is an odd case, but
+ # we better test for it anyway.
+ if (exists $options->{is} && !(exists $options->{reader} || exists $options->{writer})) {
+ if ($options->{is} eq 'ro') {
+ $options->{reader} = 'get_' . $name;
+ }
+ elsif ($options->{is} eq 'rw') {
+ $options->{reader} = 'get_' . $name;
+ $options->{writer} = 'set_' . $name;
+ }
+ delete $options->{is};
+ }
+};
+
+1;
+
+__END__
+
+=pod
+
+=cut
--- /dev/null
+
+package Moose::Policy::SingleInheritence;
+
+use constant metaclass => 'Moose::Policy::SingleInheritence::MetaClass';
+
+package Moose::Policy::SingleInheritence::MetaClass;
+use Moose;
+
+extends 'Moose::Meta::Class';
+
+before 'superclasses' => sub {
+ my ($self, @superclasses) = @_;
+ confess 'Moose::Policy::SingleInheritence in effect for ' .
+ $self->name . ', only single inheritence is allowed'
+ if scalar @superclasses > 1;
+};
+
+1;
+
+__END__
+
+=pod
+
+=cut
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More 'no_plan';
+
+BEGIN {
+ use_ok('Moose::Policy');
+}
+
+{
+ package Foo;
+
+ use Moose::Policy 'Moose::Policy::FollowPBP';
+ use Moose;
+
+ has 'bar' => (is => 'rw', default => 'Foo::bar');
+ has 'baz' => (is => 'ro', default => 'Foo::baz');
+}
+
+isa_ok(Foo->meta, 'Moose::Meta::Class');
+is(Foo->meta->attribute_metaclass, 'Moose::Policy::FollowPBP::Attribute', '... got our custom attr metaclass');
+
+isa_ok(Foo->meta->get_attribute('bar'), 'Moose::Policy::FollowPBP::Attribute');
+
+my $foo = Foo->new;
+isa_ok($foo, 'Foo');
+
+can_ok($foo, 'get_bar');
+can_ok($foo, 'set_bar');
+
+can_ok($foo, 'get_baz');
+ok(! $foo->can('set_baz'), 'without setter');
+
+is($foo->get_bar, 'Foo::bar', '... got the right default value');
+is($foo->get_baz, 'Foo::baz', '... got the right default value');
+
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More 'no_plan';
+use Test::Exception;
+
+BEGIN {
+ use_ok('Moose::Policy');
+}
+
+{
+ package Foo;
+ use Moose::Policy 'Moose::Policy::SingleInheritence';
+ use Moose;
+
+ package Bar;
+ use Moose::Policy 'Moose::Policy::SingleInheritence';
+ use Moose;
+
+ extends 'Foo';
+
+ package Baz;
+ use Moose::Policy 'Moose::Policy::SingleInheritence';
+ use Moose;
+
+ ::dies_ok {
+ extends 'Foo', 'Bar';
+ } '... violating the policy';
+}
+
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+
+all_pod_files_ok();
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+
+all_pod_coverage_ok();