| 1 | package Data::Bind; | ||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 10 | our $VERSION = '0.30'; | |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 10 | our @EXPORT = qw(bind_op bind_op2); | |||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use base 'DynaLoader'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 10 | __PACKAGE__->bootstrap; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Devel::Caller qw(caller_cv caller_args); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use B (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | # XXX: Make sig take storage directly | ||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | sub bind_op { | ||||||||||||||||||||||||||||||
|
Subroutine
bind_op: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 16 | 7 | my %vars = @_; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 7 | my $sig = Data::Bind->sig(map { { var => $_, is_rw => 1 } } keys %vars); | |||||||||||||||||||||||||||||||
| 19 | 7 | $sig->[0]->bind({ positional => [ values %vars ], | |||||||||||||||||||||||||||||||
| 20 | named => {} }, 2); | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | # XXX: probably returning the var | ||||||||||||||||||||||||||||||||
| 23 | 7 | return; | |||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 17 | ▶ | sub bind_op2 { | ||||||||||||||||||||||||||||||
|
Subroutine
bind_op2: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 27 | 17 | my ($a, $b) = @_; | |||||||||||||||||||||||||||||||
| 28 | 17 | ▶ | if (ref($a) eq 'ARRAY' && ref($b) ne 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $a eq "ARRAY" and ref $b ne "ARRAY"
MC/DC0%0/2
ref $a eq "ARRAY" and ref $b ne "ARRAY"
ref $a eq "ARRAY"
ref $b ne "ARRAY"
Truth table33%1/3
A and B
A= ref $a eq "ARRAY"B= ref $b ne "ARRAY"
| |||||||||||||||||||||||||||||||||
| 29 | # binding @array := $arrayref | ||||||||||||||||||||||||||||||||
| 30 | 0 | $b = $$b; | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | 17 | _alias_a_to_b($a, $b, 0); | |||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 42 | ▶ | sub sig { | ||||||||||||||||||||||||||||||
|
Subroutine
sig: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 36 | 42 | my ($class, @sigs) = @_; | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 42 | ▶ | if (ref $sigs[0] eq 'HASH') { # one element | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 41 | @sigs = ([@sigs]); | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 42 | return Data::Bind::SigCollection->new( [ map { $class->sig_element(@$_) } @sigs ] ); | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 43 | ▶ | sub sig_element { | ||||||||||||||||||||||||||||||
|
Subroutine
sig_element: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 47 | 43 | my $class = shift; | |||||||||||||||||||||||||||||||
| 48 | 43 | my $now_named = 0; | |||||||||||||||||||||||||||||||
| 49 | 43 | my ($named, $positional, $named_slurpy) = ({}, []); | |||||||||||||||||||||||||||||||
| 50 | 43 | my $invocant; | |||||||||||||||||||||||||||||||
| 51 | my $multidim; | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 43 | for my $param (@_) { | |||||||||||||||||||||||||||||||
| 54 | 91 | ▶ | die 'more than one multidimensional slurpy argument' if $multidim; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | my $db_param = Data::Bind::Param->new | ||||||||||||||||||||||||||||||||
| 56 | ({ container_var => $param->{var}, | ||||||||||||||||||||||||||||||||
| 57 | named_only => $param->{named_only}, | ||||||||||||||||||||||||||||||||
| 58 | is_writable => $param->{is_rw}, | ||||||||||||||||||||||||||||||||
| 59 | is_copy => $param->{is_copy}, | ||||||||||||||||||||||||||||||||
| 60 | is_slurpy => $param->{is_slurpy}, | ||||||||||||||||||||||||||||||||
| 61 | invocant => $param->{invocant}, | ||||||||||||||||||||||||||||||||
| 62 | constraint => $param->{constraint}, | ||||||||||||||||||||||||||||||||
| 63 | default => $param->{default}, | ||||||||||||||||||||||||||||||||
| 64 | p5type => substr($param->{var}, 0, 1), | ||||||||||||||||||||||||||||||||
| 65 | 91 | name => substr($param->{var}, 1) }); | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 91 | $multidim = $param->{is_multidimension}; | |||||||||||||||||||||||||||||||
| 68 | 91 | ▶ | $db_param->is_slurpy(1) if $multidim; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 91 | ▶ | if ($param->{invocant}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 71 | $db_param->is_optional(1) | ||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | unless $param->{required}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 1 | $invocant = $db_param; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | elsif ($param->{named_only}) { | ||||||||||||||||||||||||||||||||
| 76 | 27 | ▶ | if ($db_param->is_slurpy) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | 10 | $named_slurpy = $db_param; | |||||||||||||||||||||||||||||||
| 78 | 10 | next; | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | 17 | $now_named = 1; | |||||||||||||||||||||||||||||||
| 81 | $db_param->is_optional(1) | ||||||||||||||||||||||||||||||||
| 82 | 17 | ▶ | unless $param->{required}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | 17 | $named->{$db_param->name} = $db_param; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | else { | ||||||||||||||||||||||||||||||||
| 86 | 63 | ▶ | unless ($db_param->is_slurpy) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 87 | 39 | ▶ | Carp::carp("positional argument after named ones") if $now_named; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||
| 89 | $db_param->is_optional(1) | ||||||||||||||||||||||||||||||||
| 90 | 63 | ▶ | if $param->{optional}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 63 | push @{$positional}, $db_param; | |||||||||||||||||||||||||||||||
| 93 | 63 | $named->{$db_param->name} = $db_param; | |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 43 | return Data::Bind::Sig->new | |||||||||||||||||||||||||||||||
| 98 | ({ named => $named, positional => $positional, | ||||||||||||||||||||||||||||||||
| 99 | is_multidimension => $multidim, | ||||||||||||||||||||||||||||||||
| 100 | invocant => $invocant, | ||||||||||||||||||||||||||||||||
| 101 | named_slurpy => $named_slurpy }); | ||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | # some higher level stuff | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 75 | ▶ | sub _get_cv { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_cv: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 107 | 75 | my $sub = shift; | |||||||||||||||||||||||||||||||
| 108 | 75 | my $gv = B::svref_2object($sub)->GV; | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 75 | ▶ | if ($gv->SAFENAME eq '__ANON__') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | # vivify a GV here | ||||||||||||||||||||||||||||||||
| 112 | 10 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 113 | 27 | my $nonce = "__ANON__::$sub"; | |||||||||||||||||||||||||||||||
| 114 | 27 | return B::svref_2object(\*$nonce)->object_2svref; | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | else { | ||||||||||||||||||||||||||||||||
| 117 | 48 | return $gv->object_2svref; | |||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | # store sig in the sig slot of the cv's gv | ||||||||||||||||||||||||||||||||
| 122 | 30 | ▶ | sub sub_signature { | ||||||||||||||||||||||||||||||
|
Subroutine
sub_signature: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 123 | 30 | my $class = shift; | |||||||||||||||||||||||||||||||
| 124 | 30 | my $sub = shift; | |||||||||||||||||||||||||||||||
| 125 | 30 | my $cv = _get_cv($sub); | |||||||||||||||||||||||||||||||
| 126 | 30 | *$cv->{sig} = Data::Bind->sig(@_); | |||||||||||||||||||||||||||||||
| 127 | 30 | return $sub; | |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 43 | ▶ | sub arg_bind { | ||||||||||||||||||||||||||||||
|
Subroutine
arg_bind: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 131 | 43 | my $cv = _get_cv(caller_cv(1)); | |||||||||||||||||||||||||||||||
| 132 | 43 | my @install_local = @{ *$cv->{sig}->bind_all($_[1], 2) }; | |||||||||||||||||||||||||||||||
| 133 | # We have to install the locals here, otherwise there can be | ||||||||||||||||||||||||||||||||
| 134 | # side-effects when it's too many levels away. | ||||||||||||||||||||||||||||||||
| 135 | 37 | for (@install_local) { | |||||||||||||||||||||||||||||||
| 136 | 1 | my ($name, $code) = @$_; | |||||||||||||||||||||||||||||||
| 137 | 10 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 138 | 10 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 139 | 1 | *{$name} = $code; | |||||||||||||||||||||||||||||||
| 140 | 1 | Data::Bind::_forget_unlocal(2); | |||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | Data::Bind - Bind and alias variables | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | use Data::Bind; | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | # bind simple variables | ||||||||||||||||||||||||||||||||
| 153 | sub foo { | ||||||||||||||||||||||||||||||||
| 154 | my $y = 10; | ||||||||||||||||||||||||||||||||
| 155 | my $x; | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | bind_op('$x' => $y); | ||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | # bind for subroutine calls | ||||||||||||||||||||||||||||||||
| 161 | Data::Bind->sub_signature | ||||||||||||||||||||||||||||||||
| 162 | (\&formalize, | ||||||||||||||||||||||||||||||||
| 163 | { var => '$title' }, | ||||||||||||||||||||||||||||||||
| 164 | { var => '&code'}, | ||||||||||||||||||||||||||||||||
| 165 | { var => '$subtitle', optional => 1 }, | ||||||||||||||||||||||||||||||||
| 166 | { var => '$case', named_only => 1 }, | ||||||||||||||||||||||||||||||||
| 167 | { var => '$justify', named_only => 1 }); | ||||||||||||||||||||||||||||||||
| 168 | sub formalize { | ||||||||||||||||||||||||||||||||
| 169 | my ($title, $subtitle, $case, $justify); | ||||||||||||||||||||||||||||||||
| 170 | Data::Bind->arg_bind(\@_); | ||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | formalize([\('this is title', sub { "some code" }) ], # positional | ||||||||||||||||||||||||||||||||
| 174 | { subtitle => \'hello'} ); #named | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | This module implements the semantics for perl6-style variable binding, | ||||||||||||||||||||||||||||||||
| 179 | as well as subroutine call argument passing and binding, in Perl 5. | ||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | Chia-liang Kao <clkao@clkao.org> | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | Copyright (c) 2006. Chia-liang Kao. All rights reserved. | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||
| 190 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | See L<http://www.perl.com/perl/misc/Artistic.html> | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | package Data::Bind::SigCollection; | ||||||||||||||||||||||||||||||||
| 197 | 10 | ▶ | use Data::Capture; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 42 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 200 | 42 | my ($class, $sigs) = @_; | |||||||||||||||||||||||||||||||
| 201 | 42 | bless $sigs, $class; | |||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | 10 | ▶ | use List::Util 'reduce'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 2 | ▶ | sub arity { | ||||||||||||||||||||||||||||||
|
Subroutine
arity: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||
| 207 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | reduce { $a + $b } map { $self->[$_]->arity } 0..$#{$self} | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | 49 | ▶ | sub bind_all { | ||||||||||||||||||||||||||||||
|
Subroutine
bind_all: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||
| 212 | 49 | my ($self, $arg, $lv) = @_; | |||||||||||||||||||||||||||||||
| 213 | 49 | my @install_local; | |||||||||||||||||||||||||||||||
| 214 | 49 | ++$lv; | |||||||||||||||||||||||||||||||
| 215 | 49 | my $i = 0; | |||||||||||||||||||||||||||||||
| 216 | 49 | my $multidim = $self->[0]->is_multidimension; | |||||||||||||||||||||||||||||||
| 217 | 49 | my @x; | |||||||||||||||||||||||||||||||
| 218 | 49 | ▶ | while (@$arg) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 219 | 51 | ▶ | my $inv = ref($arg->[0]) && ref($arg->[0]) eq 'ARRAY' ? undef : shift @$arg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $arg->[0] and ref $arg->[0] eq "ARRAY"
MC/DC50%1/2
ref $arg->[0] and ref $arg->[0] eq "ARRAY"
ref $arg->[0]
ref $arg->[0] eq "ARRAY"
Truth table66%2/3
A and B
A= ref $arg->[0]B= ref $arg->[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 220 | 51 | ▶ | last unless defined $inv || @$arg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $inv or @$arg
MC/DC0%0/2
defined $inv or @$arg
defined $inv
@$arg
Truth table66%2/3
A or B
A= defined $invB= @$arg
| |||||||||||||||||||||||||||||||||
| 221 | 51 | my $pos = shift @$arg; | |||||||||||||||||||||||||||||||
| 222 | 51 | my $named = shift @$arg; | |||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | 51 | ▶ | if ($multidim) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 225 | 2 | push @x, \Data::Capture::Overload->new( { invocant => $inv, positional => $pos, named => $named }); | |||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||||||
| 228 | 49 | ▶ | die 'wrong dimension' unless $self->[$i]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 229 | push @install_local, | ||||||||||||||||||||||||||||||||
| 230 | 49 | @{ $self->[$i++]->bind({ invocant => $inv, positional => $pos, named => $named }, $lv) }; | |||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | 41 | ▶ | if ($multidim) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 235 | 1 | $self->[0]->bind( { positional => \@x }, $lv ); | |||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 41 | return \@install_local; | |||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | 6 | ▶ | sub is_compatible { | ||||||||||||||||||||||||||||||
|
Subroutine
is_compatible: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 243 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||
| 244 | 10 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 245 | 6 | ▶ | local *Data::Bind::Param::slurpy_bind = sub {}; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 246 | 6 | ▶ | local *Data::Bind::Param::bind = sub {}; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 247 | 6 | ▶ | local *Data::Bind::Array::bind = sub {}; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 248 | 6 | local $@; | |||||||||||||||||||||||||||||||
| 249 | 6 | eval { $self->bind_all(\@_) }; | |||||||||||||||||||||||||||||||
| 250 | 6 | ▶ | return $@ ? 0 : 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | 8 | ▶ | sub bind { | ||||||||||||||||||||||||||||||
|
Subroutine
bind: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||
| 254 | # XXX: old api | ||||||||||||||||||||||||||||||||
| 255 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||
| 256 | 8 | ▶ | die 'old api used with multidimension sig' if $#{$self}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 257 | 8 | ▶ | $self->[0]->bind($_[0], $_[1] || 2); | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[1] || 2
MC/DC0%0/1
$_[1] || 2
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub prepare_binding { | ||||||||||||||||||||||||||||||
|
Subroutine
prepare_binding: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 261 | 0 | shift->[0]->prepare_binding(@_); | |||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub finalize_binding { | ||||||||||||||||||||||||||||||
|
Subroutine
finalize_binding: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 265 | 0 | my ( $self, $binding, $lv ) = @_; | |||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | $lv ||= 1; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$lv ||= 1
MC/DC0%0/1
$lv ||= 1
$lv
Truth table0%0/2
A
A= $lv
| |||||||||||||||||||||||||||||||||
| 267 | 0 | $self->[0]->finalize_binding($binding, $lv + 1); | |||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | sub all_variable_names { | ||||||||||||||||||||||||||||||
|
Subroutine
all_variable_names: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | my %seen; grep { !$seen{$_}++ or die "duplicate variable $_ in signature" } $_[0][0]->all_variable_names; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
!$seen{$_}++ || die("duplicate variable $_ in signature")
MC/DC0%0/1
!$seen{$_}++ || die("duplicate variable $_ in signature")
!$seen{$_}++
Truth table0%0/2
not(A)
A= !$seen{$_}++
| |||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | package Data::Bind::Sig; | ||||||||||||||||||||||||||||||||
| 275 | 10 | ▶ | use base 'Class::Accessor::Fast'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 276 | 10 | __PACKAGE__->mk_accessors(qw(positional invocant named named_slurpy is_multidimension)); | |||||||||||||||||||||||||||||||
| 277 | 10 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 278 | 10 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 279 | 10 | ▶ | use PadWalker qw(peek_my); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | 10 | ▶ | use Data::Capture; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | 67 | ▶ | sub bind { | ||||||||||||||||||||||||||||||
|
Subroutine
bind: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 284 | 67 | my ( $self, $args, $lv ) = @_; | |||||||||||||||||||||||||||||||
| 285 | 67 | ▶ | $lv ||= 1; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$lv ||= 1
MC/DC100%1/1
$lv ||= 1
$lv
Truth table100%2/2
A
A= $lv
| |||||||||||||||||||||||||||||||||
| 286 | 67 | $self->finalize_binding( $self->prepare_binding(Data::Capture->new($args)), $lv + 1 ); | |||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | 67 | ▶ | sub prepare_binding { | ||||||||||||||||||||||||||||||
|
Subroutine
prepare_binding: called CC=22 SCAR=31.5
| |||||||||||||||||||||||||||||||||
| 290 | 67 | my ($self, $capture, %opts) = @_; | |||||||||||||||||||||||||||||||
| 291 | 67 | local $Carp::CarpLevel = 2; | |||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | 67 | my %bound; | |||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | 67 | my $named_arg = $capture->named; | |||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | 67 | my $bindings; | |||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | # FIXME invocant should be ref, it's writable in perl5 | ||||||||||||||||||||||||||||||||
| 300 | 67 | ▶ | if ($self->invocant) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | croak 'invocant missing' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 302 | if !defined $capture->invocant; | ||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||
| 304 | 1 | $bindings->{$self->invocant->container_var} = [ $self->invocant, \$capture->invocant ]; | |||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||
| 306 | else { | ||||||||||||||||||||||||||||||||
| 307 | 65 | ▶ | croak 'unexpected invocant' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 308 | if defined $capture->invocant; | ||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | 66 | ▶ | for my $param_name (keys %{$self->named || {}}) { | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->named || {}
MC/DC0%0/1
$self->named || {}
$self->named
Truth table50%1/2
A
A= $self->named
| |||||||||||||||||||||||||||||||||
| 312 | 147 | my $param = $self->named->{$param_name}; | |||||||||||||||||||||||||||||||
| 313 | 147 | ▶ | if (my $current = delete $named_arg->{$param_name}) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 314 | # XXX: handle array concating | ||||||||||||||||||||||||||||||||
| 315 | 31 | $bindings->{ $param->container_var } = [ $param, $current ]; | |||||||||||||||||||||||||||||||
| 316 | 31 | $bound{$param_name}++; | |||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||
| 318 | elsif ($param->default) { | ||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | $bindings->{ $param->container_var } = [ $param, $opts{no_defaults} ? undef : \$param->default->(), 'default' ]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||
| 321 | elsif ($param->named_only) { | ||||||||||||||||||||||||||||||||
| 322 | 24 | ▶ | croak "named argument ".$param->name." is required" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 323 | unless $param->is_optional; | ||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||
| 327 | 61 | ▶ | if ($self->named_slurpy) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 328 | 21 | $bindings->{ $self->named_slurpy->container_var } = | |||||||||||||||||||||||||||||||
| 329 | [ $self->named_slurpy, $named_arg, 'slurpy' ]; | ||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||
| 331 | else { | ||||||||||||||||||||||||||||||||
| 332 | # XXX: report extra incoming named args | ||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||
| 335 | 61 | my $pos_arg = $capture->positional; | |||||||||||||||||||||||||||||||
| 336 | 61 | ▶ | for my $param (@{$self->positional || []}) { | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->positional || []
MC/DC100%1/1
$self->positional || []
$self->positional
Truth table100%2/2
A
A= $self->positional
| |||||||||||||||||||||||||||||||||
| 337 | 93 | ▶ | if ($param->is_slurpy && $param->p5type ne '$') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$param->is_slurpy and $param->p5type ne "\$"
MC/DC100%2/2
$param->is_slurpy and $param->p5type ne "\$"
$param->is_slurpy
$param->p5type ne "\$"
Truth table100%3/3
A and B
A= $param->is_slurpyB= $param->p5type ne "\$"
| |||||||||||||||||||||||||||||||||
| 338 | 28 | $bindings->{ $param->container_var } = [ $param, $pos_arg, 'slurpy' ]; | |||||||||||||||||||||||||||||||
| 339 | 28 | $pos_arg = []; | |||||||||||||||||||||||||||||||
| 340 | 28 | last; | |||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||
| 342 | 65 | ▶ | next if $bound{$param->name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 343 | 57 | my $current = shift @$pos_arg; | |||||||||||||||||||||||||||||||
| 344 | # XXX crap logic, simplify me | ||||||||||||||||||||||||||||||||
| 345 | 57 | ▶ | unless ($current) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||
| 347 | 7 | ▶ | if ($param->default) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | $bindings->{ $param->container_var } = [ $param, $opts{no_defaults} ? undef : \$param->default->(), "default" ]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 349 | 0 | next; | |||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | 7 | ▶ | last if $param->is_optional; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 353 | 2 | croak "positional argument ".$param->name." is required"; | |||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | 50 | $bindings->{ $param->container_var } = [ $param, $current ]; | |||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||
| 357 | # extra incoming positional args | ||||||||||||||||||||||||||||||||
| 358 | 59 | ▶ | if (@$pos_arg) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 359 | 3 | croak "extra positional argument."; | |||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | 56 | return $bindings; | |||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | 56 | ▶ | sub finalize_binding { | ||||||||||||||||||||||||||||||
|
Subroutine
finalize_binding: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 366 | 56 | my ( $self, $bindings, $lv ) = @_; | |||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||
| 368 | 56 | ▶ | $lv ||= 1; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$lv ||= 1
MC/DC0%0/1
$lv ||= 1
$lv
Truth table50%1/2
A
A= $lv
| |||||||||||||||||||||||||||||||||
| 369 | 56 | my $pad = peek_my($lv); | |||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||
| 371 | 116 | ▶ | my @ret = map { $_->[2] ? $_->[0]->slurpy_bind($_->[1], $lv, $pad) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 372 | 56 | : $_->[0]->bind($_->[1], $lv, $pad) } values %{ $bindings }; | |||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||
| 374 | 55 | return \@ret; | |||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||
| 378 | 2 | ▶ | sub arity { | ||||||||||||||||||||||||||||||
|
Subroutine
arity: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 379 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 380 | 2 | scalar grep { !$_->is_optional } values %{$self->named}; | |||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | sub all_variable_names { | ||||||||||||||||||||||||||||||
|
Subroutine
all_variable_names: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 384 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 385 | 0 | my %seen; | |||||||||||||||||||||||||||||||
| 386 | return ( | ||||||||||||||||||||||||||||||||
| 387 | 0 | grep { !$seen{$_}++ } map { $_->container_var } grep { defined } ( | |||||||||||||||||||||||||||||||
| 388 | 0 | @{ $self->positional }, | |||||||||||||||||||||||||||||||
| 389 | # FIXME also invocant | ||||||||||||||||||||||||||||||||
| 390 | 0 | @{ $self->named }{ sort keys %{ $self->named } }, | |||||||||||||||||||||||||||||||
| 391 | $self->named_slurpy, | ||||||||||||||||||||||||||||||||
| 392 | ) | ||||||||||||||||||||||||||||||||
| 393 | ); | ||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||
| 396 | package Data::Bind::Param; | ||||||||||||||||||||||||||||||||
| 397 | 10 | ▶ | use base 'Class::Accessor::Fast'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 398 | 10 | __PACKAGE__->mk_accessors(qw(name p5type is_optional is_writable is_copy is_slurpy container_var named_only constraint default)); | |||||||||||||||||||||||||||||||
| 399 | 10 | ▶ | use Devel::LexAlias qw(lexalias); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||
| 401 | 47 | ▶ | sub slurpy_bind { | ||||||||||||||||||||||||||||||
|
Subroutine
slurpy_bind: called CC=8 SCAR=21.0
| |||||||||||||||||||||||||||||||||
| 402 | 47 | my ($self, $vars, $lv, $pad) = @_; | |||||||||||||||||||||||||||||||
| 403 | 47 | $lv++; | |||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||
| 405 | 47 | ▶ | my $ref = $pad->{$self->container_var} or Carp::confess $self->container_var; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||
| 407 | 47 | ▶ | if ($self->p5type eq '@') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 408 | 28 | my $i = 0; | |||||||||||||||||||||||||||||||
| 409 | # flatten | ||||||||||||||||||||||||||||||||
| 410 | 28 | for my $var (@$vars) { | |||||||||||||||||||||||||||||||
| 411 | 47 | ▶ | if (ref($var) eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 412 | 4 | Data::Bind::_av_store($ref, $i++, \$var->[$_]) for 0..$#{$var}; | |||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||
| 414 | else { | ||||||||||||||||||||||||||||||||
| 415 | 43 | Data::Bind::_av_store($ref, $i++, $var); | |||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||
| 418 | 28 | return; | |||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||
| 420 | 19 | ▶ | if ($self->p5type eq '%') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 421 | Data::Bind::_hv_store($ref, $_, $vars->{$_}) | ||||||||||||||||||||||||||||||||
| 422 | 19 | for keys %$vars; | |||||||||||||||||||||||||||||||
| 423 | 19 | return; | |||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||
| 425 | 0 | die "not yet"; | |||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | 59 | ▶ | sub bind { | ||||||||||||||||||||||||||||||
|
Subroutine
bind: called CC=13 SCAR=27.4
| |||||||||||||||||||||||||||||||||
| 429 | 59 | my ($self, $var, $lv, $pad) = @_; | |||||||||||||||||||||||||||||||
| 430 | 59 | $lv++; | |||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||
| 432 | 59 | ▶ | if ( my $constraint = $self->constraint ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 433 | 2 | ▶ | unless ( $constraint->(ref $var eq 'SCALAR' ? $$var : $var, level => $lv, pad => $pad, var => $var, param => $self) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 434 | 1 | die "Failed constraint of param " . $self->name; | |||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||
| 438 | 58 | ▶ | if ($self->p5type eq '&') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 439 | 1 | return [ (caller($lv-1))[0].'::'.$self->name => $$var ]; | |||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||
| 441 | 57 | ▶ | my $ref = $pad->{$self->container_var} or Carp::confess $self->container_var; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 442 | 57 | ▶ | if ($self->p5type eq '$') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 443 | # XXX: check $var type etc, take additional ref | ||||||||||||||||||||||||||||||||
| 444 | 53 | ▶ | if ($self->is_copy) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 445 | 0 | $$ref = $$var; | |||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||
| 447 | elsif ($self->is_writable) { | ||||||||||||||||||||||||||||||||
| 448 | 9 | lexalias($lv, $self->container_var, $var); | |||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||
| 450 | else { | ||||||||||||||||||||||||||||||||
| 451 | 44 | ▶ | if (ref($var) eq 'ARRAY' || ref($var) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
ref $var eq "ARRAY" or ref $var eq "HASH"
MC/DC0%0/2
ref $var eq "ARRAY" or ref $var eq "HASH"
ref $var eq "ARRAY"
ref $var eq "HASH"
Truth table33%1/3
A or B
A= ref $var eq "ARRAY"B= ref $var eq "HASH"
| |||||||||||||||||||||||||||||||||
| 452 | 0 | Data::Bind::_alias_a_to_b($ref, \$var, 1); | |||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||
| 454 | elsif (defined $$var) { | ||||||||||||||||||||||||||||||||
| 455 | 44 | Data::Bind::_alias_a_to_b($ref, $var, 1); | |||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||
| 458 | 53 | return; | |||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||
| 460 | 4 | ▶ | if ($self->p5type eq '@') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 461 | 4 | Data::Bind::_alias_a_to_b($ref, $var, !$self->is_writable); | |||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||
| 463 | else { | ||||||||||||||||||||||||||||||||
| 464 | 0 | die 'not yet'; | |||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||
| 466 | 4 | return; | |||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||
| 469 | package Data::Bind::Array; | ||||||||||||||||||||||||||||||||
| 470 | 10 | ▶ | use base 'Tie::Array'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||
| 472 | 10 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 473 | 10 | $_[0]->{real}->[$_[1]]; | |||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||
| 476 | 3 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 477 | 3 | $_[0]->{real}->[$_[1]] = $_[2]; | |||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||
| 480 | 13 | ▶ | sub FETCHSIZE { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCHSIZE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 481 | 13 | scalar @{$_[0]->{real}}; | |||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||
| 484 | 10 | 1; | |||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||
| 488 | L<Sub::Multi> | ||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||
| 490 | B<TODO: > Add a good reference to Perl6 multiple dispatch here. | ||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||
| 492 | B<TODO: > Add a good reference to Perl6 variable binding semantics | ||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||
| 494 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||
| 496 | Chia-liang Kao E<lt>clkao@clkao.orgE<gt> | ||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||
| 498 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||
| 500 | Copyright 2006 by Chia-liang Kao and others. | ||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||
| 502 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||
| 503 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||
| 505 | See L<http://www.perl.com/perl/misc/Artistic.html> | ||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||
| 507 | =cut | ||||||||||||||||||||||||||||||||