Kavorka/TraitFor/Parameter/alias.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 64 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use 5.014;
2 use strict;
3 use warnings;
4  
5 package Kavorka::TraitFor::Parameter::alias;
6  
7 our $AUTHORITY = 'cpan:TOBYINK';
8 our $VERSION = '0.039';
9  
10 use Moo::Role;
11  
12 around _injection_assignment => sub
13 {
14 my $next = shift;
15 my $self = shift;
16 my ($sig, $var, $val) = @_;
17
18 if ($] >= 5.022)
19 {
20 # in some future version of Perl, should be able to set $pragma=''
21 my $pragma = "use experimental 'refaliasing';no warnings 'experimental::refaliasing';";
22 my $kind = $self->kind;
23 $kind = 'local' unless $kind eq 'my' || $kind eq 'our';
24 return sprintf('%s %s; { %s\\%s = \\ do { %s } };', $kind, $var, $pragma, $var, $val);
25 }
26 elsif ($self->kind eq 'my')
27 {
28 require Data::Alias;
29 return sprintf('Data::Alias::alias(my %s = do { %s });', $var, $val);
30 }
31 elsif ($self->kind eq 'our')
32 {
33 (my $glob = $var) =~ s/\A./*/;
34 return sprintf('our %s; local %s = \\do { %s };', $var, $glob, $val);
35 }
36 else
37 {
38 (my $glob = $var) =~ s/\A./*/;
39 return sprintf('local %s = \\do { %s };', $glob, $val);
40 }
41 };
42  
43 after sanity_check => sub
44 {
45 my $self = shift;
46
47 my $traits = $self->traits;
48 my $name = $self->name;
49
50 croak("Parameter $name cannot be an alias and coerce") if $traits->{coerce};
51 croak("Parameter $name cannot be an alias and a copy") if $traits->{copy};
52 croak("Parameter $name cannot be an alias and locked") if $traits->{locked};
53 };
54  
55 1;