package MyApp {
use MooX::Press class => ['Foo', 'Bar'];
}
my $thing1 = MyApp::Foo->new();
my $thing2 = MyApp->new_foo(); # alternative constructor
####
package MyApp::Zoo;
use MooX::Press (
role => [
'Aquatic' => {
can => [
swim => sub { print "swimming\n" },
],
},
'Flight',
],
class => [
'Animal' => {
has => [qw( $name $colour $age )],
subclass => [
'Fish' => {
with => 'Aquatic',
subclass => [qw( Shark Ray )],
},
'Bird' => { with => 'Flight' },
'Mammal' => {
subclass => [
qw( Panda Goat ),
'Kangaroo' => { can => [ jump => sub { ... } ] },
'Dolphin' => { with => 'Aquatic' },
'Bat' => { with => 'Flight' },
],
},
],
},
],
);
####
use Moo;
use MyApp::Zoo::Types qw(Kangaroo);
has mascot => (is => 'ro', isa => Kangaroo);
####
use MyApp::Zoo::Types qw(is_Kangaroo);
$thing->jump if is_Kangaroo($thing);
####
use MyApp::Zoo ();
my $lenny = MyApp::Zoo->new_shark(name => 'Lenny');
$lenny->isa('MyApp::Zoo::Shark'); # true
$lenny->isa('MyApp::Zoo::Fish'); # true
$lenny->isa('MyApp::Zoo::Animal'); # true
$lenny->does('MyApp::Zoo::Aquatic'); # true
$lenny->can('swim'); # true
package MyApp::Zoo::Enclosure::Tank {
use Moo;
use Types::Standard qw(ArrayRef);
use MyApp::Zoo::Types qw(Aquatic);
has animals => (
is => 'rw',
isa => ArrayRef[Aquatic],
);
}
my $tank = MyApp::Zoo::Enclosure::Tank->new(
animals => [ $lenny ],
);