Last active
December 11, 2015 10:19
-
-
Save tobyink/4586048 to your computer and use it in GitHub Desktop.
This file contains 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
use v5.14; | |
use strict; | |
use warnings; | |
package My::Role | |
{ | |
use Moose::Role; | |
my $some_val; | |
sub has_my { | |
my ( $self, $value ) = @_; | |
$some_val //= $value; | |
return $some_val; | |
} | |
sub has_our { | |
my ( $self, $value ) = @_; | |
our $other_val //= $value; | |
return $other_val; | |
} | |
} | |
package Object1 | |
{ | |
use Moose; | |
with 'My::Role'; | |
} | |
package Object2 | |
{ | |
use Moose; | |
with 'My::Role'; | |
} | |
my $first = Object1->new; | |
my $second = Object2->new; | |
$first->has_my(7); | |
say $second->has_my; | |
$first->has_our(7); | |
say $second->has_our; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment