Skip to content

Instantly share code, notes, and snippets.

@tobyink
Last active December 11, 2015 10:19
Show Gist options
  • Save tobyink/4586048 to your computer and use it in GitHub Desktop.
Save tobyink/4586048 to your computer and use it in GitHub Desktop.
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