sub import {
$CALLER = caller();
+
+ strict->import;
+ warnings->import;
# we should never export to main
return if $CALLER eq 'main';
sub import {
$CALLER = caller();
+
+ strict->import;
+ warnings->import;
# we should never export to main
return if $CALLER eq 'main';
}
{
- package Point;
- use strict;
- use warnings;
+ package Point;
use Moose;
has 'x' => (isa => 'Int', is => 'ro');
}
package Point3D;
- use strict;
- use warnings;
use Moose;
extends 'Point';
{
package BankAccount;
- use strict;
- use warnings;
use Moose;
has 'balance' => (isa => 'Num', is => 'rw', default => 0);
$self->balance($current_balance - $amount);
}
- package CheckingAccount;
- use strict;
- use warnings;
+ package CheckingAccount;
use Moose;
extends 'BankAccount';
{
package BinaryTree;
- use strict;
- use warnings;
use Moose;
has 'node' => (is => 'rw', isa => 'Any');
{
package Address;
- use strict;
- use warnings;
use Moose;
use Moose::Util::TypeConstraints;
has 'zip_code' => (is => 'rw', isa => 'USZipCode');
package Company;
- use strict;
- use warnings;
use Moose;
use Moose::Util::TypeConstraints;
};
package Person;
- use strict;
- use warnings;
use Moose;
has 'first_name' => (is => 'rw', isa => 'Str', required => 1);
}
package Employee;
- use strict;
- use warnings;
use Moose;
extends 'Person';
{
package Request;
- use strict;
- use warnings;
use Moose;
use Moose::Util::TypeConstraints;
{
package Eq;
- use strict;
- use warnings;
use Moose::Role;
requires 'equal_to';
}
package Comparable;
- use strict;
- use warnings;
use Moose::Role;
with 'Eq';
}
package Printable;
- use strict;
- use warnings;
use Moose::Role;
requires 'to_string';
{
package US::Currency;
- use strict;
- use warnings;
use Moose;
with 'Comparable', 'Printable';
{
package Bar;
- use strict;
- use warnings;
use Moose;
eval { extends 'Foo'; };
{
package Baz;
- use strict;
- use warnings;
use Moose;
eval { extends 'Bar'; };
{
package Foo::Bar;
- use strict;
- use warnings;
use Moose;
eval { extends 'Foo', 'Bar'; };
{
package Bling;
- use strict;
- use warnings;
use Moose;
eval { extends 'No::Class'; };
{
package Foo;
- use strict;
- use warnings;
use Moose;
sub foo { 'Foo::foo' }
sub baz { 'Foo::baz' }
package Bar;
- use strict;
- use warnings;
use Moose;
extends 'Foo';
override bar => sub { 'Bar::bar -> ' . super() };
package Baz;
- use strict;
- use warnings;
use Moose;
extends 'Bar';
{
package Bling;
- use strict;
- use warnings;
use Moose;
sub bling { 'Bling::bling' }
package Bling::Bling;
- use strict;
- use warnings;
use Moose;
extends 'Bling';
{
package Foo;
- use strict;
- use warnings;
use Moose;
sub foo { 'Foo::foo(' . (inner() || '') . ')' }
sub baz { 'Foo::baz(' . (inner() || '') . ')' }
package Bar;
- use strict;
- use warnings;
use Moose;
extends 'Foo';
augment bar => sub { 'Bar::bar' };
package Baz;
- use strict;
- use warnings;
use Moose;
extends 'Bar';
{
package Bling;
- use strict;
- use warnings;
use Moose;
sub bling { 'Bling::bling' }
package Bling::Bling;
- use strict;
- use warnings;
use Moose;
extends 'Bling';
{
package Foo;
- use strict;
- use warnings;
use Moose;
sub foo { 'Foo::foo(' . (inner() || '') . ')' };
sub bar { 'Foo::bar(' . (inner() || '') . ')' }
package Bar;
- use strict;
- use warnings;
use Moose;
extends 'Foo';
override 'bar' => sub { 'Bar::bar -> ' . super() };
package Baz;
- use strict;
- use warnings;
use Moose;
extends 'Bar';
sub baz { 'Foo::baz' }
package Bar;
- use strict;
- use warnings;
use Moose;
extends 'Foo';
override bar => sub { 'Bar::bar -> ' . super() };
package Baz;
- use strict;
- use warnings;
use Moose;
extends 'Bar';
--- /dev/null
+#!/usr/bin/perl
+
+use Test::More tests => 10;
+
+# for classes ...
+{
+ package Foo;
+ use Moose;
+
+ eval '$foo = 5;';
+ ::ok($@, '... got an error because strict is on');
+ ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error');
+
+ {
+ my $warn;
+ local $SIG{__WARN__} = sub { $warn = $_[0] };
+
+ ::ok(!$warn, '... no warning yet');
+
+ eval 'my $bar = 1 + "hello"';
+
+ ::ok($warn, '... got a warning');
+ ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
+ }
+}
+
+# and for roles ...
+{
+ package Bar;
+ use Moose::Role;
+
+ eval '$foo = 5;';
+ ::ok($@, '... got an error because strict is on');
+ ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error');
+
+ {
+ my $warn;
+ local $SIG{__WARN__} = sub { $warn = $_[0] };
+
+ ::ok(!$warn, '... no warning yet');
+
+ eval 'my $bar = 1 + "hello"';
+
+ ::ok($warn, '... got a warning');
+ ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning');
+ }
+}
\ No newline at end of file
sub no_moose { $_[0]->{no_moose} }
- package Foo::Moose;
- use strict;
- use warnings;
+ package Foo::Moose;
use Moose;
extends 'Elk';
sub foo { 'Foo::foo' }
- package Bar;
- use strict;
- use warnings;
-
+ package Bar;
use base 'Foo';
-
use Moose;
sub new { (shift)->meta->new_object(@_) }
package Baz;
- use strict;
- use warnings;
use Moose;
use base 'Foo';
}
{ # now seee if Moose will override it
package Foo;
- use strict;
- use warnings;
use Moose;
}
{
package Bar;
- use strict;
- use warnings;
use Moose;
has 'foo' => (is => 'rw', isa => 'Foo');
{
package Foo;
- use strict;
- use warnings;
use Moose;
eval {
{
package Foo;
- use strict;
- use warnings;
use Moose;
eval {
{
package Foo;
- use strict;
- use warnings;
use Moose;
eval {
{
package Foo;
- use strict;
- use warnings;
use Moose;
has 'bar' => (is => 'rw',
package Bar;
- use strict;
- use warnings;
use Moose;
has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);
package Baz;
- use strict;
- use warnings;
use Moose;
has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);
{
package Bling;
- use strict;
- use warnings;
use Moose;
::dies_ok {
{
package Bling::Bling;
- use strict;
- use warnings;
use Moose;
::dies_ok {
{
package Foo::Role;
- use strict;
- use warnings;
use Moose::Role;
# if does() exists on its own, then
has 'bar' => (is => 'rw', does => 'Bar::Role');
package Bar::Role;
- use strict;
- use warnings;
use Moose::Role;
# if isa and does appear together, then see if Class->does(Role)
has 'foo' => (is => 'rw', isa => 'Foo::Class', does => 'Foo::Role');
package Foo::Class;
- use strict;
- use warnings;
use Moose;
with 'Foo::Role';
package Bar::Class;
- use strict;
- use warnings;
use Moose;
with 'Bar::Role';
{
package Baz::Class;
- use strict;
- use warnings;
use Moose;
# if isa and does appear together, then see if Class->does(Role)
sub bling { 'Bling::bling' }
package Bling::Bling;
- use strict;
- use warnings;
use Moose;
# if isa and does appear together, then see if Class->does(Role)
{
package Foo;
- use strict;
- use warnings;
use Moose;
has 'bar' => (is => 'ro', required => 1);
{
package Foo::Meta::Attribute;
- use strict;
- use warnings;
use Moose;
extends 'Moose::Meta::Attribute';
};
package Foo;
- use strict;
- use warnings;
use Moose;
has 'foo' => (metaclass => 'Foo::Meta::Attribute');
{
package Bar::Meta::Attribute;
- use strict;
- use warnings;
use Moose;
extends 'Class::MOP::Attribute';
package Bar;
- use strict;
- use warnings;
use Moose;
::lives_ok {
{
package Foo;
- use strict;
- use warnings;
use Moose;
has 'bar' => (is => 'rw', isa => 'ArrayRef | HashRef');
{
package Bar;
- use strict;
- use warnings;
use Moose;
has 'baz' => (is => 'rw', isa => 'Str | CodeRef');
{
package Foo;
- use strict;
- use warnings;
use Moose;
use Moose::Util::TypeConstraints;
has 'other_fail';
package Bar;
- use strict;
- use warnings;
use Moose;
extends 'Foo';
{
package Foo;
- use strict;
- use warnings;
use Moose;
has 'bar' => (is => 'rw', default => 10);
package Bar;
- use strict;
- use warnings;
use Moose;
has 'foo' => (
{
package Engine;
- use strict;
- use warnings;
use Moose;
sub go { 'Engine::go' }
sub stop { 'Engine::stop' }
package Car;
- use strict;
- use warnings;
use Moose;
has 'engine' => (
{
package Baz;
- use strict;
- use warnings;
use Moose;
sub foo { 'Baz::foo' }
sub boo { 'Baz::boo' }
package Baz::Proxy1;
- use strict;
- use warnings;
use Moose;
has 'baz' => (
);
package Baz::Proxy2;
- use strict;
- use warnings;
use Moose;
has 'baz' => (
);
package Baz::Proxy3;
- use strict;
- use warnings;
use Moose;
has 'baz' => (
{
package FooRole;
-
- use strict;
- use warnings;
use Moose::Role;
our $VERSION = '0.01';
{
package FooRole;
- use strict;
- use warnings;
use Moose::Role;
has 'bar' => (is => 'rw', isa => 'FooClass');
};
package BarClass;
- use strict;
- use warnings;
use Moose;
sub boo { 'BarClass::boo' }
sub foo { 'BarClass::foo' } # << the role overrides this ...
package FooClass;
- use strict;
- use warnings;
use Moose;
extends 'BarClass';
{
package Foo::Role;
- use strict;
- use warnings;
use Moose::Role;
requires 'foo';
# classes which does not implement required method
{
package Foo::Class;
- use strict;
- use warnings;
use Moose;
::dies_ok { with('Foo::Role') } '... no foo method implemented by Foo::Class';
# class which does implement required method
{
package Bar::Class;
- use strict;
- use warnings;
use Moose;
::dies_ok { with('Foo::Class') } '... cannot consume a class, it must be a role';
# role which does implement required method
{
package Bar::Role;
- use strict;
- use warnings;
use Moose::Role;
::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Role';
# role which does not implement required method
{
package Baz::Role;
- use strict;
- use warnings;
use Moose::Role;
::lives_ok { with('Foo::Role') } '... no foo method implemented by Baz::Role';
# classes which does not implement required method
{
package Baz::Class;
- use strict;
- use warnings;
use Moose;
::dies_ok { with('Baz::Role') } '... no foo method implemented by Baz::Class2';
# class which does implement required method
{
package Baz::Class2;
- use strict;
- use warnings;
use Moose;
::lives_ok { with('Baz::Role') } '... has a foo method implemented by Baz::Class2';
{
package Role::Foo;
- use strict;
- use warnings;
use Moose::Role;
requires 'foo';
sub bar { 'Role::Foo::bar' }
package Role::Bar;
- use strict;
- use warnings;
use Moose::Role;
requires 'bar';
{
package My::Test1;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... our mutually recursive roles combine okay';
package My::Test2;
- use strict;
- use warnings;
use Moose;
::lives_ok {
{
package Role::Bling;
- use strict;
- use warnings;
use Moose::Role;
sub bling { 'Role::Bling::bling' }
package Role::Bling::Bling;
- use strict;
- use warnings;
use Moose::Role;
sub bling { 'Role::Bling::Bling::bling' }
{
package My::Test3;
- use strict;
- use warnings;
use Moose;
::throws_ok {
} qr/requires the method \'bling\' to be implemented/, '... role methods conflicted and method was required';
package My::Test4;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... role methods didnt conflict when manually combined';
package My::Test5;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... role methods didnt conflict when manually combined (in opposite order)';
package My::Test6;
- use strict;
- use warnings;
use Moose;
::lives_ok {
{
package Role::Bling::Bling::Bling;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Bling::Bling';
{
package Role::Boo;
- use strict;
- use warnings;
use Moose::Role;
has 'ghost' => (is => 'ro', default => 'Role::Boo::ghost');
package Role::Boo::Hoo;
- use strict;
- use warnings;
use Moose::Role;
has 'ghost' => (is => 'ro', default => 'Role::Boo::Hoo::ghost');
{
package My::Test7;
- use strict;
- use warnings;
use Moose;
::throws_ok {
'... role attrs conflicted and method was required';
package My::Test8;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... role attrs didnt conflict when manually combined';
package My::Test9;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... role attrs didnt conflict when manually combined';
package My::Test10;
- use strict;
- use warnings;
use Moose;
has 'ghost' => (is => 'ro', default => 'My::Test10::ghost');
{
package Role::Plot;
- use strict;
- use warnings;
use Moose::Role;
override 'twist' => sub {
};
package Role::Truth;
- use strict;
- use warnings;
use Moose::Role;
override 'twist' => sub {
{
package My::Test::Base;
- use strict;
- use warnings;
use Moose;
sub twist { 'My::Test::Base::twist' }
package My::Test11;
- use strict;
- use warnings;
use Moose;
extends 'My::Test::Base';
} '... composed the role with override okay';
package My::Test12;
- use strict;
- use warnings;
use Moose;
extends 'My::Test::Base';
} '... composed the role with override okay';
package My::Test13;
- use strict;
- use warnings;
use Moose;
::dies_ok {
} '... cannot compose it because we have no superclass';
package My::Test14;
- use strict;
- use warnings;
use Moose;
extends 'My::Test::Base';
{
package Role::Reality;
- use strict;
- use warnings;
use Moose::Role;
::throws_ok {
{
package Molecule;
- use strict;
- use warnings;
use Moose::Role;
package Molecule::Organic;
- use strict;
- use warnings;
use Moose::Role;
with 'Molecule';
excludes 'Molecule::Inorganic';
package Molecule::Inorganic;
- use strict;
- use warnings;
use Moose::Role;
with 'Molecule';
{
package My::Test1;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... adding the role (w/ excluded roles) okay';
package My::Test2;
- use strict;
- use warnings;
use Moose;
::throws_ok {
'... adding the role w/ excluded role conflict dies okay';
package My::Test3;
- use strict;
- use warnings;
use Moose;
::lives_ok {
{
package Methane;
- use strict;
- use warnings;
use Moose;
with 'Molecule::Organic';
package My::Test4;
- use strict;
- use warnings;
use Moose;
extends 'Methane';
{
package Class::ProvideFoo::Base;
- use strict;
- use warnings;
use Moose;
sub foo { 'Class::ProvideFoo::Base::foo' }
package Class::ProvideFoo::Override1;
- use strict;
- use warnings;
use Moose;
extends 'Class::ProvideFoo::Base';
override 'foo' => sub { 'Class::ProvideFoo::foo' };
package Class::ProvideFoo::Override2;
- use strict;
- use warnings;
use Moose;
extends 'Class::ProvideFoo::Base';
{
package Class::ProvideFoo::Before1;
- use strict;
- use warnings;
use Moose;
extends 'Class::ProvideFoo::Base';
before 'foo' => sub { 'Class::ProvideFoo::foo:before' };
package Class::ProvideFoo::Before2;
- use strict;
- use warnings;
use Moose;
extends 'Class::ProvideFoo::Base';
} '... the required "foo" method exists, but it is a before (and we will die)';
package Class::ProvideFoo::Before3;
- use strict;
- use warnings;
use Moose;
extends 'Class::ProvideFoo::Base';
before 'foo' => sub { 'Class::ProvideFoo::foo:before' };
package Class::ProvideFoo::Before4;
- use strict;
- use warnings;
use Moose;
extends 'Class::ProvideFoo::Base';
} '... the required "foo" method exists in the symbol table (and we will live)';
package Class::ProvideFoo::Before5;
- use strict;
- use warnings;
use Moose;
extends 'Class::ProvideFoo::Base';
{
package Class::ProvideFoo::Attr1;
- use strict;
- use warnings;
use Moose;
extends 'Class::ProvideFoo::Base';
has 'foo' => (is => 'ro');
package Class::ProvideFoo::Attr2;
- use strict;
- use warnings;
use Moose;
extends 'Class::ProvideFoo::Base';
{
package Role::Base;
- use strict;
- use warnings;
use Moose::Role;
sub foo { 'Role::Base::foo' }
package Role::Derived1;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Base';
package Role::Derived2;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Base';
package My::Test::Class1;
- use strict;
- use warnings;
use Moose;
::lives_ok {
{
package Role::Base2;
- use strict;
- use warnings;
use Moose::Role;
override 'foo' => sub { super() . ' -> Role::Base::foo' };
package Role::Derived3;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Base2';
package Role::Derived4;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Base2';
package My::Test::Class2::Base;
- use strict;
- use warnings;
use Moose;
sub foo { 'My::Test::Class2::Base' }
package My::Test::Class2;
- use strict;
- use warnings;
use Moose;
extends 'My::Test::Class2::Base';
{
package Role::Base3;
- use strict;
- use warnings;
use Moose::Role;
around 'foo' => sub { 'Role::Base::foo(' . (shift)->() . ')' };
package Role::Derived5;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Base3';
package Role::Derived6;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Base3';
package My::Test::Class3::Base;
- use strict;
- use warnings;
use Moose;
sub foo { 'My::Test::Class3::Base' }
package My::Test::Class3;
- use strict;
- use warnings;
use Moose;
extends 'My::Test::Class3::Base';
{
package Role::Base4;
- use strict;
- use warnings;
use Moose::Role;
has 'foo' => (is => 'ro', default => 'Role::Base::foo');
package Role::Derived7;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Base4';
package Role::Derived8;
- use strict;
- use warnings;
use Moose::Role;
with 'Role::Base4';
package My::Test::Class4;
- use strict;
- use warnings;
use Moose;
::lives_ok {
{
package HTTPHeader;
- use strict;
- use warnings;
use Moose;
has 'array' => (is => 'ro');
{
package HTTPHeader;
- use strict;
- use warnings;
use Moose;
use Moose::Util::TypeConstraints;
{
package My::Meta::Class;
- use strict;
- use warnings;
use Moose;
extends 'Moose::Meta::Class';
{
package My::Meta::Attribute::DefaultReadOnly;
- use strict;
- use warnings;
use Moose;
extends 'Moose::Meta::Attribute';
{
package Foo;
- use strict;
- use warnings;
use Moose;
package Bar;
{
package Constraint;
- use strict;
- use warnings;
use Moose::Role;
has 'value' => (isa => 'Num', is => 'ro');
sub error_message { confess "Abstract method!" }
package Constraint::OnLength;
- use strict;
- use warnings;
use Moose::Role;
has 'units' => (isa => 'Str', is => 'ro');
{
package Constraint::AtLeast;
- use strict;
- use warnings;
use Moose;
with 'Constraint';
sub error_message { 'must be at least ' . (shift)->value; }
package Constraint::NoMoreThan;
- use strict;
- use warnings;
use Moose;
with 'Constraint';
sub error_message { 'must be no more than ' . (shift)->value; }
package Constraint::LengthNoMoreThan;
- use strict;
- use warnings;
use Moose;
extends 'Constraint::NoMoreThan';
with 'Constraint::OnLength';
package Constraint::LengthAtLeast;
- use strict;
- use warnings;
use Moose;
extends 'Constraint::AtLeast';
BEGIN {
package Moose::POOP::Meta::Instance;
- use strict;
- use warnings;
use Moose;
use DBM::Deep;
}
package Moose::POOP::Meta::Class;
- use strict;
- use warnings;
use Moose;
extends 'Moose::Meta::Class';
}
{
package Moose::POOP::Object;
- use strict;
- use warnings;
use metaclass 'Moose::POOP::Meta::Class' => (
':instance_metaclass' => 'Moose::POOP::Meta::Instance'
);
}
{
package Newswriter::Author;
- use strict;
- use warnings;
use Moose;
extends 'Moose::POOP::Object';
has 'last_name' => (is => 'rw', isa => 'Str');
package Newswriter::Article;
- use strict;
- use warnings;
use Moose;
use Moose::Util::TypeConstraints;
{
package List;
- use strict;
- use warnings;
use Moose::Role;
has '_list' => (
}
package List::Immutable;
- use strict;
- use warnings;
use Moose::Role;
requires 'head';
}
package My::List1;
- use strict;
- use warnings;
use Moose;
::lives_ok {
} '... successfully composed roles together';
package My::List2;
- use strict;
- use warnings;
use Moose;
::lives_ok {
package Bar;
-use strict;
-use warnings;
use Moose;
use Moose::Util::TypeConstraints;
package Foo;
-use strict;
-use warnings;
use Moose;
has 'bar' => (is => 'rw');
package MyMooseA;
-use strict;
-use warnings;
use Moose;
has 'b' => (is => 'rw', isa => 'MyMooseB');
package MyMooseB;
-use strict;
-use warnings;
use Moose;
1;
\ No newline at end of file