# lib/Wildlife/Behavior/Buyer.zydeco.pm
role Buyer {
requires money;
method acquire ( Num $price ) {
say "I bought !";
}
method sale ( Num $price ) {
say "I sold !";
}
}
####
# lib/Place/Behavior/Exhibit.zydeco.pm
role Exhibit {
has exhibition ( type => ArrayRef );
has artist ( type => ArrayRef );
has artwork ( type => ArrayRef )
method display {
say "Shoooow";
}
}
##
##
# lib/Art.pm
package Art {
use Zydeco;
class Place {
has space;
include Place::Behavior::Exhibit;
include Wildlife::Behavior::Buyer;
class Gallery with Exhibit, Buyer {
has artwork ( type => ArrayRef );
has artist ( type => ArrayRef );
has event ( type => ArrayRef );
has owner;
has public;
}
}
}
##
##
# t/gallery.t
use v5.16;
use Test::More;
use Art;
my $gallery = Art->new_gallery(
space => 1000,
exhibitions => [ "Foo", "Bar" ],
owner => "Arty Person",
money => 10_000_000 );
ok $gallery->does('Art::Exhibit'), 'Gallery does role Exhibit';
ok $gallery->exhibitions, 'Gallery got an exhibitions attribute';
ok $gallery->owner, 'Gallery got an owner';
can_ok $gallery, 'acquire';
can_ok $gallery, 'sale';
##
##
smonff@padi:~/projects/Art-World$ prove -lv t/15_gallery.t
t/15_gallery.t .. Can't apply Art::Buyer to Art::Gallery - missing money at /home/smonff/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/Moo/Role.pm line 307.
BEGIN failed--compilation aborted at (eval 269) line 1.
at /home/smonff/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5.32.0/B/Hooks/EndOfScope/XS.pm line 26.
Compilation failed in require at t/15_gallery.t line 3.
BEGIN failed--compilation aborted at t/15_gallery.t line 3.
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
Test Summary Report
-------------------
t/15_gallery.t (Wstat: 512 Tests: 0 Failed: 0)
Non-zero exit status: 2
Parse errors: No plan found in TAP output
Files=1, Tests=0, 2 wallclock secs ( 0.03 usr 0.00 sys + 2.00 cusr 0.10 csys = 2.13 CPU)
Result: FAIL
##
##
croak "Can't apply ${name} to ${to} - missing ".join(', ', @requires_fail);
##
##
class Gallery with Exhibit, Buyer {
has artwork ( type => ArrayRef );
has artist ( type => ArrayRef );
has event ( type => ArrayRef );
has owner;
has public;
has money;
...
}
##
##
smonff@padi:~/projects/Art-World$ prove -lv t/15_gallery.t
t/15_gallery.t ..
ok 1 - use Art;
ok 2 - Gallery does role Exhibit
ok 3 - Gallery got an exhibition attribute
ok 4 - Gallery got an owner
ok 5 - Art::Gallery->can('acquire')
ok 6 - Art::Gallery->can('serve')
ok 7 - Art::Gallery->can('sale')
1..7
ok
All tests successful.
Files=1, Tests=7, 2 wallclock secs ( 0.03 usr 0.00 sys + 2.30 cusr 0.16 csys = 2.49 CPU)
Result: PASS