• Download Gist
be-careful-when-using-any-variables-whatsoever.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
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;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.