-
-
Save peczenyj/1299589 to your computer and use it in GitHub Desktop.
Exemplo de Role + Delegation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Closeable; | |
use Moose::Role; | |
requires 'close'; | |
1; | |
package Connector; | |
use Moose; | |
has 'client' => ( | |
is => 'rw', | |
isa => 'Client', | |
required => 1, | |
handles => 'Closeable', | |
); | |
with 'Closeable'; | |
__PACKAGE__->meta->make_immutable; | |
no Moose; | |
1; | |
package Client; | |
use Moose; | |
sub close { | |
print 666; | |
} | |
__PACKAGE__->meta->make_immutable; | |
no Moose; | |
1; | |
my $c = Connector->new (client => Client->new); | |
$c->close; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment