| 1 | package Venus::Unpack; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.018; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # IMPORTS | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Venus::Class 'base', 'with'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # INHERITS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | base 'Venus::Kind::Utility'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # BUILDERS | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub build_arg { | ||||||||||||||||||||||||||
|
Subroutine
build_arg: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | return { | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | args => ref $data eq 'ARRAY' ? $data : [$data], | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # METHODS | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 37 | ▶ | sub all { | ||||||||||||||||||||||||||
|
Subroutine
all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 37 | my ($self) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 37 | $self->use(0..$#{$self->{args}}); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 37 | return $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | sub arg { | ||||||||||||||||||||||||||
|
Subroutine
arg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 3 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 3 | return $self->{args}->[$name]; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 11 | ▶ | sub args { | ||||||||||||||||||||||||||
|
Subroutine
args: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 11 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 11 | ▶ | $self->{args} = [@args] if @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return wantarray ? (@{$self->{args}}) : $self->{args}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub array { | ||||||||||||||||||||||||||
|
Subroutine
array: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | require Venus::Array; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | return Venus::Array->new(scalar $self->args); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 8 | ▶ | sub cast { | ||||||||||||||||||||||||||
|
Subroutine
cast: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 8 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 8 | require Venus::What; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 23 | ▶ | my $code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 64 | 23 | my ($self, $data, $into) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 23 | my $what = Venus::What->new($data); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 23 | ▶ | return $into ? $what->cast($into) : $what->deduce; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 8 | }; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 8 | return $self->list('foreach', $code, @args); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 9 | ▶ | sub checks { | ||||||||||||||||||||||||||
|
Subroutine
checks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 9 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 9 | require Venus::Assert; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 17 | ▶ | my $code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | 17 | my ($self, $data, $expr, $index) = @_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 17 | my $name = 'argument #' . ($index + 1); | |||||||||||||||||||||||||||
| 83 | 17 | return scalar Venus::Assert->new($name)->expression($expr)->valid($data); | |||||||||||||||||||||||||||
| 84 | 9 | }; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 9 | return $self->list('foreach', $code, @args); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | ▶ | sub copy { | ||||||||||||||||||||||||||
|
Subroutine
copy: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 3 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 3 | ▶ | for (my $i = 0; $i < @args; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 6 | my $name = $args[$i]; | |||||||||||||||||||||||||||
| 94 | 6 | my $attr = $args[$i+1]; | |||||||||||||||||||||||||||
| 95 | $self->can($attr) | ||||||||||||||||||||||||||||
| 96 | ? $self->$attr($self->get($name)) | ||||||||||||||||||||||||||||
| 97 | 6 | ▶ | : ($self->{$attr} = $self->get($name)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 3 | return $self; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 1 | ▶ | sub first { | ||||||||||||||||||||||||||
|
Subroutine
first: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 1 | ▶ | $self->use(0) if @{$self->{args}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | return $self; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 43 | ▶ | sub foreach { | ||||||||||||||||||||||||||
|
Subroutine
foreach: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | 43 | my ($self, $code, @args) = @_; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 43 | my $results = []; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 43 | ▶ | return $results if !$code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 43 | for my $name (0..$#{$self->{uses}}) { | |||||||||||||||||||||||||||
| 119 | 101 | my $data = $self->get($self->{uses}->[$name]); | |||||||||||||||||||||||||||
| 120 | 101 | ▶ | my $args = $name > $#args ? $args[-1] : $args[$name]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 101 | push @$results, $self->$code($data, $args, $name); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 36 | return $results; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 6 | ▶ | sub from { | ||||||||||||||||||||||||||
|
Subroutine
from: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 128 | 6 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 6 | ▶ | $self = $self->new if !ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 6 | ▶ | $self->{from} = ref $data || $data if $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $data || $data
MC/DC0%0/2
ref $data || $data
ref $data
$data
Truth table66%2/3
A || B
A= ref $dataB= $data
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 6 | return $self; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 118 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 118 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 118 | ▶ | return if !defined $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 117 | return $self->{args}->[$name]; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 3 | ▶ | sub into { | ||||||||||||||||||||||||||
|
Subroutine
into: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 3 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 3 | require Venus::Space; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 9 | ▶ | my $code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 151 | 9 | my ($self, $data, $name) = @_; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 9 | ▶ | return $data if UNIVERSAL::isa($data, $name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 9 | return Venus::Space->new($name)->load->new($data); | |||||||||||||||||||||||||||
| 155 | 3 | }; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 3 | return $self->list('foreach', $code, @args); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1 | ▶ | sub last { | ||||||||||||||||||||||||||
|
Subroutine
last: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 1 | ▶ | $self->use($#{$self->{args}}) if @{$self->{args}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 1 | return $self; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 47 | ▶ | sub list { | ||||||||||||||||||||||||||
|
Subroutine
list: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 169 | 47 | my ($self, $code, @args) = @_; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 47 | my $results = $self->$code(@args); | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 40 | ▶ | return wantarray ? (ref $results eq 'ARRAY' ? @$results : $results) : $results; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 3 | ▶ | sub move { | ||||||||||||||||||||||||||
|
Subroutine
move: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 3 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 3 | my %seen; | |||||||||||||||||||||||||||
| 180 | 3 | ▶ | for (my $i = 0; $i < @args; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 6 | $seen{$args[$i]}++; | |||||||||||||||||||||||||||
| 182 | 6 | my $name = $args[$i]; | |||||||||||||||||||||||||||
| 183 | 6 | my $attr = $args[$i+1]; | |||||||||||||||||||||||||||
| 184 | $self->can($attr) | ||||||||||||||||||||||||||||
| 185 | ? $self->$attr($self->get($name)) | ||||||||||||||||||||||||||||
| 186 | 6 | ▶ | : ($self->{$attr} = $self->get($name)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 3 | $self->{args} = [map $self->{args}[$_], grep !$seen{$_}++, 0..$#{$self->{args}}]; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 3 | return $self; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 10 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | 10 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 10 | ▶ | $self->{name} = $data if $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 10 | return $self; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 2 | ▶ | sub one { | ||||||||||||||||||||||||||
|
Subroutine
one: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | 2 | my ($self, $code, @args) = @_; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 2 | my $results = $self->$code(@args); | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 2 | return $results->[0]; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 2 | ▶ | sub reset { | ||||||||||||||||||||||||||
|
Subroutine
reset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 2 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 2 | ▶ | $self->{args} = [@args] if @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 2 | $self->{uses} = []; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 2 | return $self; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 5 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||
| 220 | 5 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 5 | ▶ | return $self->{args} if !@args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 4 | ▶ | return $self->{args} = $args[0] if @args == 1 && ref $args[0] eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@args == 1 and ref $args[0] eq "HASH"
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1
ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 4 | my ($index, $value) = @args; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 4 | ▶ | return if not defined $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 4 | return $self->{args}->[$index] = $value; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 8 | ▶ | sub signature { | ||||||||||||||||||||||||||
|
Subroutine
signature: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 234 | 8 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 8 | require Venus::Assert; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 8 | my (@frame_0) = ((caller(0))[0..3]); | |||||||||||||||||||||||||||
| 239 | 8 | my (@frame_1) = ((caller(1))[0..3]); | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 8 | my $file = $frame_0[1]; | |||||||||||||||||||||||||||
| 242 | 8 | my $line = $frame_0[2]; | |||||||||||||||||||||||||||
| 243 | 8 | ▶ | my $package = $self->{from} || $frame_0[0]; | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{'from'} || $frame_0[0]
MC/DC0%0/2
$self->{'from'} || $frame_0[0]
$self->{'from'}
$frame_0[0]
Truth table66%2/3
A || B
A= $self->{'from'}B= $frame_0[0]
| |||||||||||||||||||||||||||||
| 244 | 8 | ▶ | my $routine = $self->{name} || $frame_1[3]; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'name'} || $frame_1[3]
MC/DC0%0/2
$self->{'name'} || $frame_1[3]
$self->{'name'}
$frame_1[3]
Truth table33%1/3
A || B
A= $self->{'name'}B= $frame_1[3]
| |||||||||||||||||||||||||||||
| 245 | 8 | my $from = $self->{from}; | |||||||||||||||||||||||||||
| 246 | 8 | my $name = $self->{name}; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 8 | ▶ | $routine = $routine ? qq{"@{[(split /::/, $routine)[-1]]}"} : '(undefined)'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 21 | ▶ | my $code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 251 | 21 | my ($self, $data, $expr, $index) = @_; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 21 | my @name; | |||||||||||||||||||||||||||
| 254 | 21 | my $number = $index + 1; | |||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 21 | push @name, "argument #$number for signature"; | |||||||||||||||||||||||||||
| 257 | 21 | ▶ | push @name, $name ? "\"$name\"" : $routine; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 21 | ▶ | push @name, $from ? "from \"$from\"" : "in package \"$package\""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 21 | ▶ | push @name, $file =~ /\(eval\s*\d*\)/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | ? "in (eval)" : "in file \"$file\" at line $line"; | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 21 | return scalar Venus::Assert->new(join ' ', @name)->expression($expr)->validate( | |||||||||||||||||||||||||||
| 263 | $data | ||||||||||||||||||||||||||||
| 264 | ); | ||||||||||||||||||||||||||||
| 265 | 8 | }; | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 8 | return $self->list('foreach', $code, @args); | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 11 | ▶ | sub types { | ||||||||||||||||||||||||||
|
Subroutine
types: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 271 | 11 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 11 | $self->validate(@args); | |||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 9 | return $self; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 49 | ▶ | sub use { | ||||||||||||||||||||||||||
|
Subroutine
use: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 279 | 49 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 49 | $self->{uses} = [map 0+$_, @args]; | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 49 | return $self; | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 15 | ▶ | sub validate { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 287 | 15 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 15 | require Venus::Assert; | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 31 | ▶ | my $code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 292 | 31 | my ($self, $data, $expr, $index) = @_; | |||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 31 | my $name = 'argument #' . ($index + 1); | |||||||||||||||||||||||||||
| 295 | 31 | return scalar Venus::Assert->new($name)->expression($expr)->validate($data); | |||||||||||||||||||||||||||
| 296 | 15 | }; | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 15 | return $self->list('foreach', $code, @args); | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 4 | 1; | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | =head1 NAME | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | Venus::Unpack - Unpack Class | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =cut | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | =head1 ABSTRACT | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | Unpack Class for Perl 5 | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | =cut | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | package main; | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | use Venus::Unpack; | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | my $unpack = Venus::Unpack->new(args => ["hello", 123, 1.23]); | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | # my $args = $unpack->all->types('string', 'number', 'float')->args; | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # ["hello", 123, 1.23] | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | =cut | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | This package provides methods for validating, coercing, and otherwise operating | ||||||||||||||||||||||||||||
| 334 | on lists of arguments. | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | =cut | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | =head1 INHERITS | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | This package inherits behaviors from: | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | L<Venus::Kind::Utility> | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | =cut | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | =head1 METHODS | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | This package provides the following methods: | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | =cut | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | =head2 all | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | all() (Venus::Unpack) | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | The all method selects all arguments for processing returns the invocant. | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | =over 4 | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | =item all example 1 | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | # given: synopsis | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | package main; | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | $unpack = $unpack->all; | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | =back | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | =cut | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | =head2 arg | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | arg(string $index) (any) | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | The arg method returns the argument at the index specified. | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | =over 4 | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =item arg example 1 | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | # given: synopsis | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | package main; | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | my $arg = $unpack->arg(0); | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | # "hello" | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | =back | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | =over 4 | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | =item arg example 2 | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | # given: synopsis | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | package main; | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | my $arg = $unpack->arg(1); | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | # 123 | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | =back | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | =over 4 | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | =item arg example 3 | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | # given: synopsis | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | package main; | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | my $arg = $unpack->arg(2); | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | # 1.23 | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | =back | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | =cut | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | =head2 args | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | args(any @args) (arrayref) | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | The args method returns all arugments as an arrayref, or list in list context. | ||||||||||||||||||||||||||||
| 433 | If arguments are provided they will overwrite the existing arugment list. | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | =over 4 | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | =item args example 1 | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | # given: synopsis | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | package main; | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | my $args = $unpack->args; | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | # ["hello", 123, 1.23] | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | =back | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | =over 4 | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | =item args example 2 | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | # given: synopsis | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | package main; | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | my $args = $unpack->args(1.23, 123, "hello"); | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | # [1.23, 123, "hello"] | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | =back | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | =cut | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | =head2 array | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | array() (Venus::Array) | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | The array method returns the argument list as a L<Venus::Array> object. | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | =over 4 | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | =item array example 1 | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | # given: synopsis | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | package main; | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | my $array = $unpack->array; | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | # bless(..., 'Venus::Array') | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | =back | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | =cut | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | =head2 cast | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | cast(string $name) (arrayref) | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | The cast method processes the selected arguments, passing each value to the | ||||||||||||||||||||||||||||
| 496 | class name specified, or the L<Venus::What/cast> method, and returns results. | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | =over 4 | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | =item cast example 1 | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | # given: synopsis | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | package main; | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | my $cast = $unpack->all->cast; | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | # [ | ||||||||||||||||||||||||||||
| 511 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 512 | # bless(..., 'Venus::Number'), | ||||||||||||||||||||||||||||
| 513 | # bless(..., 'Venus::Float'), | ||||||||||||||||||||||||||||
| 514 | # ] | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | =back | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | =over 4 | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | =item cast example 2 | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | # given: synopsis | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | package main; | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | my $cast = $unpack->all->cast('scalar'); | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | # [ | ||||||||||||||||||||||||||||
| 529 | # bless(..., 'Venus::Scalar'), | ||||||||||||||||||||||||||||
| 530 | # bless(..., 'Venus::Scalar'), | ||||||||||||||||||||||||||||
| 531 | # bless(..., 'Venus::Scalar'), | ||||||||||||||||||||||||||||
| 532 | # ] | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | =back | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | =cut | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | =head2 checks | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | checks(string @types) (arrayref) | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | The checks method processes the selected arguments, passing each value to the | ||||||||||||||||||||||||||||
| 543 | L<Venus::Assert/check> method with the type expression provided, and returns | ||||||||||||||||||||||||||||
| 544 | results. | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | =over 4 | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | =item checks example 1 | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | # given: synopsis | ||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | package main; | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | my $checks = $unpack->all->checks('string'); | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | # [true, false, false] | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | =back | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | =over 4 | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | =item checks example 2 | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | # given: synopsis | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | package main; | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | my $checks = $unpack->all->checks('string | number'); | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | # [true, true, false] | ||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | =back | ||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | =over 4 | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | =item checks example 3 | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | # given: synopsis | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | package main; | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | my $checks = $unpack->all->checks('string | number', 'float'); | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | # [true, false, true] | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | =back | ||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | =over 4 | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | =item checks example 4 | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | # given: synopsis | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | package main; | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | my $checks = $unpack->all->checks('string', 'number', 'float'); | ||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | # [true, true, true] | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | =back | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | =over 4 | ||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | =item checks example 5 | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | # given: synopsis | ||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||
| 610 | package main; | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | my $checks = $unpack->all->checks('boolean', 'value'); | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | # [false, true, true] | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | =back | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | =cut | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | =head2 copy | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | copy(string @pairs) (Venus::Unpack) | ||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | The copy method copies values from the arugment list as properties of the | ||||||||||||||||||||||||||||
| 625 | underlying object and returns the invocant. | ||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | =over 4 | ||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||
| 631 | =item copy example 1 | ||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | # given: synopsis | ||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | package main; | ||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | $unpack = $unpack->copy(0 => 'arg1'); | ||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | # bless({..., arg1 => 'hello'}, 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | =back | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | =over 4 | ||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | =item copy example 2 | ||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | # given: synopsis | ||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | package main; | ||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||
| 651 | $unpack = $unpack->copy(0 => 'arg1', 2 => 'arg3'); | ||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | # bless({..., arg1 => 'hello', arg3 => 1.23}, 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||
| 655 | =back | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | =over 4 | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | =item copy example 3 | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | # given: synopsis | ||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | package main; | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | $unpack = $unpack->copy(0 => 'arg1', 1 => 'arg2', 2 => 'arg3'); | ||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||
| 667 | # bless({..., arg1 => 'hello', arg2 => 123, arg3 => 1.23}, 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||
| 669 | =back | ||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | =cut | ||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||
| 673 | =head2 first | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | first() (Venus::Unpack) | ||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||
| 677 | The first method selects the first argument for processing returns the | ||||||||||||||||||||||||||||
| 678 | invocant. | ||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||
| 680 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||
| 682 | =over 4 | ||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | =item first example 1 | ||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||
| 686 | # given: synopsis | ||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | package main; | ||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||
| 690 | $unpack = $unpack->first; | ||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||
| 692 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||
| 694 | =back | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | =cut | ||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | =head2 from | ||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||
| 700 | from(string $data) (Venus::Unpack) | ||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||
| 702 | The from method names the source of the unpacking operation and is used in | ||||||||||||||||||||||||||||
| 703 | exception messages whenever the L<Venus::Unpack/signature> operation fails. | ||||||||||||||||||||||||||||
| 704 | This method returns the invocant. | ||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | I<Since C<2.23>> | ||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||
| 708 | =over 4 | ||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | =item from example 1 | ||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | # given: synopsis | ||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||
| 714 | package main; | ||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||
| 716 | $unpack = $unpack->from; | ||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||
| 718 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||
| 720 | =back | ||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||
| 722 | =over 4 | ||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||
| 724 | =item from example 2 | ||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||
| 726 | # given: synopsis | ||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | package main; | ||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||
| 730 | $unpack = $unpack->from('Example'); | ||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||
| 732 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||
| 734 | =back | ||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||
| 736 | =cut | ||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||
| 738 | =head2 get | ||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||
| 740 | get(string $index) (any) | ||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||
| 742 | The get method returns the argument at the index specified. | ||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||
| 744 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||
| 746 | =over 4 | ||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||
| 748 | =item get example 1 | ||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||
| 750 | # given: synopsis | ||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||
| 752 | package main; | ||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||
| 754 | my $get = $unpack->get; | ||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||
| 756 | # undef | ||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||
| 758 | =back | ||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||
| 760 | =over 4 | ||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||
| 762 | =item get example 2 | ||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||
| 764 | # given: synopsis | ||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||
| 766 | package main; | ||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||
| 768 | my $get = $unpack->get(0); | ||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||
| 770 | # "hello" | ||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||
| 772 | =back | ||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||
| 774 | =over 4 | ||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||
| 776 | =item get example 3 | ||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||
| 778 | # given: synopsis | ||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||
| 780 | package main; | ||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||
| 782 | my $get = $unpack->get(1); | ||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||
| 784 | # 123 | ||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||
| 786 | =back | ||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||
| 788 | =over 4 | ||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||
| 790 | =item get example 4 | ||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||
| 792 | # given: synopsis | ||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||
| 794 | package main; | ||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||
| 796 | my $get = $unpack->get(2); | ||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||
| 798 | # 1.23 | ||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||
| 800 | =back | ||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||
| 802 | =over 4 | ||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||
| 804 | =item get example 5 | ||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||
| 806 | # given: synopsis | ||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||
| 808 | package main; | ||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||
| 810 | my $get = $unpack->get(3); | ||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||
| 812 | # undef | ||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||
| 814 | =back | ||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||
| 816 | =cut | ||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||
| 818 | =head2 into | ||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||
| 820 | into(string @args) (any) | ||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||
| 822 | The into method processes the selected arguments, passing each value to the | ||||||||||||||||||||||||||||
| 823 | class name specified, and returns results. | ||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||
| 825 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||
| 827 | =over 4 | ||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||
| 829 | =item into example 1 | ||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||
| 831 | # given: synopsis | ||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||
| 833 | package main; | ||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||
| 835 | my $cast = $unpack->all->into('Venus::String'); | ||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||
| 837 | # [ | ||||||||||||||||||||||||||||
| 838 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 839 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 840 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 841 | # ] | ||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||
| 843 | =back | ||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||
| 845 | =over 4 | ||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||
| 847 | =item into example 2 | ||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||
| 849 | # given: synopsis | ||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||
| 851 | package main; | ||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||
| 853 | my $cast = $unpack->all->into('Venus::String', 'Venus::Number'); | ||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||
| 855 | # [ | ||||||||||||||||||||||||||||
| 856 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 857 | # bless(..., 'Venus::Number'), | ||||||||||||||||||||||||||||
| 858 | # bless(..., 'Venus::Number'), | ||||||||||||||||||||||||||||
| 859 | # ] | ||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||
| 861 | =back | ||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||
| 863 | =over 4 | ||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||
| 865 | =item into example 3 | ||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||
| 867 | # given: synopsis | ||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||
| 869 | package main; | ||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||
| 871 | my $cast = $unpack->all->into('Venus::String', 'Venus::Number', 'Venus::Float'); | ||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||
| 873 | # [ | ||||||||||||||||||||||||||||
| 874 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 875 | # bless(..., 'Venus::Number'), | ||||||||||||||||||||||||||||
| 876 | # bless(..., 'Venus::Float'), | ||||||||||||||||||||||||||||
| 877 | # ] | ||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||
| 879 | =back | ||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||
| 881 | =cut | ||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||
| 883 | =head2 last | ||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||
| 885 | last() (Venus::Unpack) | ||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||
| 887 | The last method selects the last argument for processing returns the | ||||||||||||||||||||||||||||
| 888 | invocant. | ||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||
| 890 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||
| 892 | =over 4 | ||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||
| 894 | =item last example 1 | ||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||
| 896 | # given: synopsis | ||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||
| 898 | package main; | ||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||
| 900 | $unpack = $unpack->last; | ||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||
| 902 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||
| 904 | =back | ||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||
| 906 | =cut | ||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||
| 908 | =head2 list | ||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||
| 910 | list(string | coderef $code, any @args) (arrayref) | ||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||
| 912 | The list method returns the result of the dispatched method call as an | ||||||||||||||||||||||||||||
| 913 | arrayref, or list in list context. | ||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||
| 915 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||
| 917 | =over 4 | ||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||
| 919 | =item list example 1 | ||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||
| 921 | # given: synopsis | ||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||
| 923 | package main; | ||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||
| 925 | my (@args) = $unpack->all->list('cast'); | ||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||
| 927 | # ( | ||||||||||||||||||||||||||||
| 928 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 929 | # bless(..., 'Venus::Number'), | ||||||||||||||||||||||||||||
| 930 | # bless(..., 'Venus::Float'), | ||||||||||||||||||||||||||||
| 931 | # ) | ||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||
| 933 | =back | ||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||
| 935 | =over 4 | ||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | =item list example 2 | ||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||
| 939 | # given: synopsis | ||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||
| 941 | package main; | ||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||
| 943 | my ($string) = $unpack->all->list('cast'); | ||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||
| 945 | # ( | ||||||||||||||||||||||||||||
| 946 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 947 | # ) | ||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||
| 949 | =back | ||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||
| 951 | =over 4 | ||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||
| 953 | =item list example 3 | ||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||
| 955 | # given: synopsis | ||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||
| 957 | package main; | ||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||
| 959 | my (@args) = $unpack->all->list('cast', 'string'); | ||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||
| 961 | # ( | ||||||||||||||||||||||||||||
| 962 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 963 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 964 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 965 | # ) | ||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||
| 967 | =back | ||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||
| 969 | =over 4 | ||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||
| 971 | =item list example 4 | ||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||
| 973 | # given: synopsis | ||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||
| 975 | package main; | ||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||
| 977 | my (@args) = $unpack->use(0,2)->list('cast', 'string', 'float'); | ||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||
| 979 | # ( | ||||||||||||||||||||||||||||
| 980 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 981 | # bless(..., 'Venus::Float'), | ||||||||||||||||||||||||||||
| 982 | # ) | ||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||
| 984 | =back | ||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||
| 986 | =cut | ||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||
| 988 | =head2 move | ||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||
| 990 | move(string @pairs) (Venus::Unpack) | ||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||
| 992 | The move method moves values from the arugment list, reducing the arugment | ||||||||||||||||||||||||||||
| 993 | list, as properties of the underlying object and returns the invocant. | ||||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||
| 995 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||
| 997 | =over 4 | ||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||
| 999 | =item move example 1 | ||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||
| 1001 | # given: synopsis | ||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||
| 1003 | package main; | ||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||
| 1005 | $unpack = $unpack->move(0 => 'arg1'); | ||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||
| 1007 | # bless({..., arg1 => 'hello'}, 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||
| 1009 | =back | ||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||
| 1011 | =over 4 | ||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||
| 1013 | =item move example 2 | ||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||
| 1015 | # given: synopsis | ||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||
| 1017 | package main; | ||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||
| 1019 | $unpack = $unpack->move(0 => 'arg1', 2 => 'arg3'); | ||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||
| 1021 | # bless({..., arg1 => 'hello', arg3 => 1.23}, 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||
| 1023 | =back | ||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||
| 1025 | =over 4 | ||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||
| 1027 | =item move example 3 | ||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||
| 1029 | # given: synopsis | ||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||
| 1031 | package main; | ||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||
| 1033 | $unpack = $unpack->move(0 => 'arg1', 1 => 'arg2', 2 => 'arg3'); | ||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||
| 1035 | # bless({..., arg1 => 'hello', arg2 => 123, arg3 => 1.23}, 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||
| 1037 | =back | ||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||
| 1039 | =cut | ||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||
| 1041 | =head2 name | ||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||
| 1043 | name(string $data) (Venus::Unpack) | ||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||
| 1045 | The name method names the unpacking operation and is used in exception messages | ||||||||||||||||||||||||||||
| 1046 | whenever the L<Venus::Unpack/signature> operation fails. This method returns | ||||||||||||||||||||||||||||
| 1047 | the invocant. | ||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||
| 1049 | I<Since C<2.23>> | ||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||
| 1051 | =over 4 | ||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||
| 1053 | =item name example 1 | ||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||
| 1055 | # given: synopsis | ||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||
| 1057 | package main; | ||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||
| 1059 | $unpack = $unpack->name; | ||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||
| 1061 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||
| 1063 | =back | ||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||
| 1065 | =over 4 | ||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||
| 1067 | =item name example 2 | ||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||
| 1069 | # given: synopsis | ||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||
| 1071 | package main; | ||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||
| 1073 | $unpack = $unpack->name('example'); | ||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||
| 1075 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||
| 1077 | =back | ||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||
| 1079 | =cut | ||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||
| 1081 | =head2 new | ||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||
| 1083 | new(any @args) (Venus::Unpack) | ||||||||||||||||||||||||||||
| 1084 | |||||||||||||||||||||||||||||
| 1085 | The new method constructs an instance of the package. | ||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||
| 1087 | I<Since C<4.15>> | ||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||
| 1089 | =over 4 | ||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||
| 1091 | =item new example 1 | ||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||
| 1093 | package main; | ||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||
| 1095 | use Venus::Unpack; | ||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||
| 1097 | my $new = Venus::Unpack->new; | ||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||
| 1099 | # bless(..., "Venus::Unpack") | ||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||
| 1101 | =back | ||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||
| 1103 | =over 4 | ||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||
| 1105 | =item new example 2 | ||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||
| 1107 | package main; | ||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||
| 1109 | use Venus::Unpack; | ||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||
| 1111 | my $new = Venus::Unpack->new(args => ["hello", 123, 1.23]); | ||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||
| 1113 | # bless(..., "Venus::Unpack") | ||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||
| 1115 | =back | ||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||
| 1117 | =cut | ||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||
| 1119 | =head2 one | ||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||
| 1121 | one(string | coderef $code, any @args) (any) | ||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||
| 1123 | The one method returns the first result of the dispatched method call. | ||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||
| 1125 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||
| 1127 | =over 4 | ||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||
| 1129 | =item one example 1 | ||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||
| 1131 | # given: synopsis | ||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||
| 1133 | package main; | ||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||
| 1135 | my $one = $unpack->all->one('cast'); | ||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||
| 1137 | # ( | ||||||||||||||||||||||||||||
| 1138 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 1139 | # ) | ||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||
| 1141 | =back | ||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||
| 1143 | =over 4 | ||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||
| 1145 | =item one example 2 | ||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||
| 1147 | # given: synopsis | ||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||
| 1149 | package main; | ||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||
| 1151 | my $one = $unpack->all->one('cast', 'string'); | ||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||
| 1153 | # ( | ||||||||||||||||||||||||||||
| 1154 | # bless(..., 'Venus::String'), | ||||||||||||||||||||||||||||
| 1155 | # ) | ||||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||
| 1157 | =back | ||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||
| 1159 | =cut | ||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||
| 1161 | =head2 reset | ||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||
| 1163 | reset(any @args) (Venus::Unpack) | ||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||
| 1165 | The reset method resets the arugments list (if provided) and deselects all | ||||||||||||||||||||||||||||
| 1166 | arguments (selected for processing) and returns the invocant. | ||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||
| 1168 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 1169 | |||||||||||||||||||||||||||||
| 1170 | =over 4 | ||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||
| 1172 | =item reset example 1 | ||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||
| 1174 | # given: synopsis | ||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||
| 1176 | package main; | ||||||||||||||||||||||||||||
| 1177 | |||||||||||||||||||||||||||||
| 1178 | $unpack = $unpack->all->reset; | ||||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||
| 1180 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||
| 1182 | =back | ||||||||||||||||||||||||||||
| 1183 | |||||||||||||||||||||||||||||
| 1184 | =over 4 | ||||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||
| 1186 | =item reset example 2 | ||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||
| 1188 | # given: synopsis | ||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||
| 1190 | package main; | ||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||
| 1192 | $unpack = $unpack->all->reset(1.23, 123, "hello"); | ||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||
| 1194 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||
| 1196 | =back | ||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||
| 1198 | =cut | ||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||
| 1200 | =head2 set | ||||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||
| 1202 | set(string $index, any $value) (any) | ||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||
| 1204 | The set method assigns the value provided at the index specified and returns | ||||||||||||||||||||||||||||
| 1205 | the value. | ||||||||||||||||||||||||||||
| 1206 | |||||||||||||||||||||||||||||
| 1207 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 1208 | |||||||||||||||||||||||||||||
| 1209 | =over 4 | ||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||
| 1211 | =item set example 1 | ||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||
| 1213 | # given: synopsis | ||||||||||||||||||||||||||||
| 1214 | |||||||||||||||||||||||||||||
| 1215 | package main; | ||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||
| 1217 | my $set = $unpack->set; | ||||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||
| 1219 | # ["hello", 123, 1.23] | ||||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||
| 1221 | =back | ||||||||||||||||||||||||||||
| 1222 | |||||||||||||||||||||||||||||
| 1223 | =over 4 | ||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||
| 1225 | =item set example 2 | ||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||
| 1227 | # given: synopsis | ||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||
| 1229 | package main; | ||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||
| 1231 | my $set = $unpack->set(0, 'howdy'); | ||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||
| 1233 | # "howdy" | ||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||
| 1235 | =back | ||||||||||||||||||||||||||||
| 1236 | |||||||||||||||||||||||||||||
| 1237 | =over 4 | ||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||
| 1239 | =item set example 3 | ||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||
| 1241 | # given: synopsis | ||||||||||||||||||||||||||||
| 1242 | |||||||||||||||||||||||||||||
| 1243 | package main; | ||||||||||||||||||||||||||||
| 1244 | |||||||||||||||||||||||||||||
| 1245 | my $set = $unpack->set(1, 987); | ||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||
| 1247 | # 987 | ||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||
| 1249 | =back | ||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||
| 1251 | =over 4 | ||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||
| 1253 | =item set example 4 | ||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||
| 1255 | # given: synopsis | ||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||
| 1257 | package main; | ||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||
| 1259 | my $set = $unpack->set(2, 12.3); | ||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||
| 1261 | # 12.3 | ||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||
| 1263 | =back | ||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||
| 1265 | =over 4 | ||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||
| 1267 | =item set example 5 | ||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||
| 1269 | # given: synopsis | ||||||||||||||||||||||||||||
| 1270 | |||||||||||||||||||||||||||||
| 1271 | package main; | ||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||
| 1273 | my $set = $unpack->set(3, 'goodbye'); | ||||||||||||||||||||||||||||
| 1274 | |||||||||||||||||||||||||||||
| 1275 | # "goodbye" | ||||||||||||||||||||||||||||
| 1276 | |||||||||||||||||||||||||||||
| 1277 | =back | ||||||||||||||||||||||||||||
| 1278 | |||||||||||||||||||||||||||||
| 1279 | =cut | ||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||
| 1281 | =head2 signature | ||||||||||||||||||||||||||||
| 1282 | |||||||||||||||||||||||||||||
| 1283 | signature(string $name, string @types) (arrayref) | ||||||||||||||||||||||||||||
| 1284 | |||||||||||||||||||||||||||||
| 1285 | The signature method processes the selected arguments, passing each value to | ||||||||||||||||||||||||||||
| 1286 | the L<Venus::Assert/validate> method with the type expression provided and | ||||||||||||||||||||||||||||
| 1287 | throws an exception on failure and otherise returns the results as an arrayref, | ||||||||||||||||||||||||||||
| 1288 | or as a list in list context. | ||||||||||||||||||||||||||||
| 1289 | |||||||||||||||||||||||||||||
| 1290 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 1291 | |||||||||||||||||||||||||||||
| 1292 | =over 4 | ||||||||||||||||||||||||||||
| 1293 | |||||||||||||||||||||||||||||
| 1294 | =item signature example 1 | ||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||
| 1296 | # given: synopsis | ||||||||||||||||||||||||||||
| 1297 | |||||||||||||||||||||||||||||
| 1298 | package main; | ||||||||||||||||||||||||||||
| 1299 | |||||||||||||||||||||||||||||
| 1300 | my ($string, $number, $float) = $unpack->all->name('example-1')->signature( | ||||||||||||||||||||||||||||
| 1301 | 'string | number | float', | ||||||||||||||||||||||||||||
| 1302 | ); | ||||||||||||||||||||||||||||
| 1303 | |||||||||||||||||||||||||||||
| 1304 | # ("hello", 123, 1.23) | ||||||||||||||||||||||||||||
| 1305 | |||||||||||||||||||||||||||||
| 1306 | =back | ||||||||||||||||||||||||||||
| 1307 | |||||||||||||||||||||||||||||
| 1308 | =over 4 | ||||||||||||||||||||||||||||
| 1309 | |||||||||||||||||||||||||||||
| 1310 | =item signature example 2 | ||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||
| 1312 | # given: synopsis | ||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||
| 1314 | package main; | ||||||||||||||||||||||||||||
| 1315 | |||||||||||||||||||||||||||||
| 1316 | my ($string, $number, $float) = $unpack->all->name('example-2')->signature( | ||||||||||||||||||||||||||||
| 1317 | 'string', 'number', 'float', | ||||||||||||||||||||||||||||
| 1318 | ); | ||||||||||||||||||||||||||||
| 1319 | |||||||||||||||||||||||||||||
| 1320 | # ("hello", 123, 1.23) | ||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||
| 1322 | =back | ||||||||||||||||||||||||||||
| 1323 | |||||||||||||||||||||||||||||
| 1324 | =over 4 | ||||||||||||||||||||||||||||
| 1325 | |||||||||||||||||||||||||||||
| 1326 | =item signature example 3 | ||||||||||||||||||||||||||||
| 1327 | |||||||||||||||||||||||||||||
| 1328 | # given: synopsis | ||||||||||||||||||||||||||||
| 1329 | |||||||||||||||||||||||||||||
| 1330 | package main; | ||||||||||||||||||||||||||||
| 1331 | |||||||||||||||||||||||||||||
| 1332 | my $results = $unpack->all->name('example-3')->signature( | ||||||||||||||||||||||||||||
| 1333 | 'string', 'number', | ||||||||||||||||||||||||||||
| 1334 | ); | ||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||
| 1336 | # Exception! (isa Venus::Check::Error) | ||||||||||||||||||||||||||||
| 1337 | |||||||||||||||||||||||||||||
| 1338 | =back | ||||||||||||||||||||||||||||
| 1339 | |||||||||||||||||||||||||||||
| 1340 | =over 4 | ||||||||||||||||||||||||||||
| 1341 | |||||||||||||||||||||||||||||
| 1342 | =item signature example 4 | ||||||||||||||||||||||||||||
| 1343 | |||||||||||||||||||||||||||||
| 1344 | # given: synopsis | ||||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||
| 1346 | package main; | ||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||
| 1348 | my $results = $unpack->all->name('example-4')->signature( | ||||||||||||||||||||||||||||
| 1349 | 'string', | ||||||||||||||||||||||||||||
| 1350 | ); | ||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||
| 1352 | # Exception! (isa Venus::Check::Error) | ||||||||||||||||||||||||||||
| 1353 | |||||||||||||||||||||||||||||
| 1354 | =back | ||||||||||||||||||||||||||||
| 1355 | |||||||||||||||||||||||||||||
| 1356 | =over 4 | ||||||||||||||||||||||||||||
| 1357 | |||||||||||||||||||||||||||||
| 1358 | =item signature example 5 | ||||||||||||||||||||||||||||
| 1359 | |||||||||||||||||||||||||||||
| 1360 | # given: synopsis | ||||||||||||||||||||||||||||
| 1361 | |||||||||||||||||||||||||||||
| 1362 | package main; | ||||||||||||||||||||||||||||
| 1363 | |||||||||||||||||||||||||||||
| 1364 | my $results = $unpack->all->name('example-5')->from('t/Venus_Unpack.t')->signature( | ||||||||||||||||||||||||||||
| 1365 | 'object', | ||||||||||||||||||||||||||||
| 1366 | ); | ||||||||||||||||||||||||||||
| 1367 | |||||||||||||||||||||||||||||
| 1368 | # Exception! (isa Venus::Check::Error) | ||||||||||||||||||||||||||||
| 1369 | |||||||||||||||||||||||||||||
| 1370 | =back | ||||||||||||||||||||||||||||
| 1371 | |||||||||||||||||||||||||||||
| 1372 | =cut | ||||||||||||||||||||||||||||
| 1373 | |||||||||||||||||||||||||||||
| 1374 | =head2 types | ||||||||||||||||||||||||||||
| 1375 | |||||||||||||||||||||||||||||
| 1376 | types(string @types) (Venus::Unpack) | ||||||||||||||||||||||||||||
| 1377 | |||||||||||||||||||||||||||||
| 1378 | The types method processes the selected arguments, passing each value to the | ||||||||||||||||||||||||||||
| 1379 | L<Venus::Assert/validate> method with the type expression provided, and unlike | ||||||||||||||||||||||||||||
| 1380 | the L</validate> method returns the invocant. | ||||||||||||||||||||||||||||
| 1381 | |||||||||||||||||||||||||||||
| 1382 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 1383 | |||||||||||||||||||||||||||||
| 1384 | =over 4 | ||||||||||||||||||||||||||||
| 1385 | |||||||||||||||||||||||||||||
| 1386 | =item types example 1 | ||||||||||||||||||||||||||||
| 1387 | |||||||||||||||||||||||||||||
| 1388 | # given: synopsis | ||||||||||||||||||||||||||||
| 1389 | |||||||||||||||||||||||||||||
| 1390 | package main; | ||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||
| 1392 | $unpack = $unpack->all->types('string | number | float'); | ||||||||||||||||||||||||||||
| 1393 | |||||||||||||||||||||||||||||
| 1394 | # bless({...}, 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1395 | |||||||||||||||||||||||||||||
| 1396 | =back | ||||||||||||||||||||||||||||
| 1397 | |||||||||||||||||||||||||||||
| 1398 | =over 4 | ||||||||||||||||||||||||||||
| 1399 | |||||||||||||||||||||||||||||
| 1400 | =item types example 2 | ||||||||||||||||||||||||||||
| 1401 | |||||||||||||||||||||||||||||
| 1402 | # given: synopsis | ||||||||||||||||||||||||||||
| 1403 | |||||||||||||||||||||||||||||
| 1404 | package main; | ||||||||||||||||||||||||||||
| 1405 | |||||||||||||||||||||||||||||
| 1406 | $unpack = $unpack->all->types('string', 'number', 'float'); | ||||||||||||||||||||||||||||
| 1407 | |||||||||||||||||||||||||||||
| 1408 | # bless({...}, 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1409 | |||||||||||||||||||||||||||||
| 1410 | =back | ||||||||||||||||||||||||||||
| 1411 | |||||||||||||||||||||||||||||
| 1412 | =over 4 | ||||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||
| 1414 | =item types example 3 | ||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||
| 1416 | # given: synopsis | ||||||||||||||||||||||||||||
| 1417 | |||||||||||||||||||||||||||||
| 1418 | package main; | ||||||||||||||||||||||||||||
| 1419 | |||||||||||||||||||||||||||||
| 1420 | $unpack = $unpack->all->types('string', 'number'); | ||||||||||||||||||||||||||||
| 1421 | |||||||||||||||||||||||||||||
| 1422 | # Exception! (isa Venus::Error) | ||||||||||||||||||||||||||||
| 1423 | |||||||||||||||||||||||||||||
| 1424 | # argument #3 error | ||||||||||||||||||||||||||||
| 1425 | |||||||||||||||||||||||||||||
| 1426 | =back | ||||||||||||||||||||||||||||
| 1427 | |||||||||||||||||||||||||||||
| 1428 | =over 4 | ||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||
| 1430 | =item types example 4 | ||||||||||||||||||||||||||||
| 1431 | |||||||||||||||||||||||||||||
| 1432 | # given: synopsis | ||||||||||||||||||||||||||||
| 1433 | |||||||||||||||||||||||||||||
| 1434 | package main; | ||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||
| 1436 | $unpack = $unpack->all->types('string'); | ||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||
| 1438 | # Exception! (isa Venus::Error) | ||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||
| 1440 | # argument #2 error | ||||||||||||||||||||||||||||
| 1441 | |||||||||||||||||||||||||||||
| 1442 | =back | ||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||
| 1444 | =cut | ||||||||||||||||||||||||||||
| 1445 | |||||||||||||||||||||||||||||
| 1446 | =head2 use | ||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||
| 1448 | use(number @args) (Venus::Unpack) | ||||||||||||||||||||||||||||
| 1449 | |||||||||||||||||||||||||||||
| 1450 | The use method selects the arguments specified (by index) for processing | ||||||||||||||||||||||||||||
| 1451 | returns the invocant. | ||||||||||||||||||||||||||||
| 1452 | |||||||||||||||||||||||||||||
| 1453 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 1454 | |||||||||||||||||||||||||||||
| 1455 | =over 4 | ||||||||||||||||||||||||||||
| 1456 | |||||||||||||||||||||||||||||
| 1457 | =item use example 1 | ||||||||||||||||||||||||||||
| 1458 | |||||||||||||||||||||||||||||
| 1459 | # given: synopsis | ||||||||||||||||||||||||||||
| 1460 | |||||||||||||||||||||||||||||
| 1461 | package main; | ||||||||||||||||||||||||||||
| 1462 | |||||||||||||||||||||||||||||
| 1463 | $unpack = $unpack->use(1,2); | ||||||||||||||||||||||||||||
| 1464 | |||||||||||||||||||||||||||||
| 1465 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1466 | |||||||||||||||||||||||||||||
| 1467 | =back | ||||||||||||||||||||||||||||
| 1468 | |||||||||||||||||||||||||||||
| 1469 | =over 4 | ||||||||||||||||||||||||||||
| 1470 | |||||||||||||||||||||||||||||
| 1471 | =item use example 2 | ||||||||||||||||||||||||||||
| 1472 | |||||||||||||||||||||||||||||
| 1473 | # given: synopsis | ||||||||||||||||||||||||||||
| 1474 | |||||||||||||||||||||||||||||
| 1475 | package main; | ||||||||||||||||||||||||||||
| 1476 | |||||||||||||||||||||||||||||
| 1477 | $unpack = $unpack->use(1,0); | ||||||||||||||||||||||||||||
| 1478 | |||||||||||||||||||||||||||||
| 1479 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1480 | |||||||||||||||||||||||||||||
| 1481 | =back | ||||||||||||||||||||||||||||
| 1482 | |||||||||||||||||||||||||||||
| 1483 | =over 4 | ||||||||||||||||||||||||||||
| 1484 | |||||||||||||||||||||||||||||
| 1485 | =item use example 3 | ||||||||||||||||||||||||||||
| 1486 | |||||||||||||||||||||||||||||
| 1487 | # given: synopsis | ||||||||||||||||||||||||||||
| 1488 | |||||||||||||||||||||||||||||
| 1489 | package main; | ||||||||||||||||||||||||||||
| 1490 | |||||||||||||||||||||||||||||
| 1491 | $unpack = $unpack->use(2,1,0); | ||||||||||||||||||||||||||||
| 1492 | |||||||||||||||||||||||||||||
| 1493 | # bless(..., 'Venus::Unpack') | ||||||||||||||||||||||||||||
| 1494 | |||||||||||||||||||||||||||||
| 1495 | =back | ||||||||||||||||||||||||||||
| 1496 | |||||||||||||||||||||||||||||
| 1497 | =cut | ||||||||||||||||||||||||||||
| 1498 | |||||||||||||||||||||||||||||
| 1499 | =head2 validate | ||||||||||||||||||||||||||||
| 1500 | |||||||||||||||||||||||||||||
| 1501 | validate(string @types) (Venus::Unpack) | ||||||||||||||||||||||||||||
| 1502 | |||||||||||||||||||||||||||||
| 1503 | The validate method processes the selected arguments, passing each value to the | ||||||||||||||||||||||||||||
| 1504 | L<Venus::Assert/validate> method with the type expression provided and throws | ||||||||||||||||||||||||||||
| 1505 | an exception on failure and otherise returns the resuts. | ||||||||||||||||||||||||||||
| 1506 | |||||||||||||||||||||||||||||
| 1507 | I<Since C<2.01>> | ||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||
| 1509 | =over 4 | ||||||||||||||||||||||||||||
| 1510 | |||||||||||||||||||||||||||||
| 1511 | =item validate example 1 | ||||||||||||||||||||||||||||
| 1512 | |||||||||||||||||||||||||||||
| 1513 | # given: synopsis | ||||||||||||||||||||||||||||
| 1514 | |||||||||||||||||||||||||||||
| 1515 | package main; | ||||||||||||||||||||||||||||
| 1516 | |||||||||||||||||||||||||||||
| 1517 | my $results = $unpack->all->validate('string | number | float'); | ||||||||||||||||||||||||||||
| 1518 | |||||||||||||||||||||||||||||
| 1519 | # ["hello", 123, 1.23] | ||||||||||||||||||||||||||||
| 1520 | |||||||||||||||||||||||||||||
| 1521 | =back | ||||||||||||||||||||||||||||
| 1522 | |||||||||||||||||||||||||||||
| 1523 | =over 4 | ||||||||||||||||||||||||||||
| 1524 | |||||||||||||||||||||||||||||
| 1525 | =item validate example 2 | ||||||||||||||||||||||||||||
| 1526 | |||||||||||||||||||||||||||||
| 1527 | # given: synopsis | ||||||||||||||||||||||||||||
| 1528 | |||||||||||||||||||||||||||||
| 1529 | package main; | ||||||||||||||||||||||||||||
| 1530 | |||||||||||||||||||||||||||||
| 1531 | my $results = $unpack->all->validate('string', 'number', 'float'); | ||||||||||||||||||||||||||||
| 1532 | |||||||||||||||||||||||||||||
| 1533 | # ["hello", 123, 1.23] | ||||||||||||||||||||||||||||
| 1534 | |||||||||||||||||||||||||||||
| 1535 | =back | ||||||||||||||||||||||||||||
| 1536 | |||||||||||||||||||||||||||||
| 1537 | =over 4 | ||||||||||||||||||||||||||||
| 1538 | |||||||||||||||||||||||||||||
| 1539 | =item validate example 3 | ||||||||||||||||||||||||||||
| 1540 | |||||||||||||||||||||||||||||
| 1541 | # given: synopsis | ||||||||||||||||||||||||||||
| 1542 | |||||||||||||||||||||||||||||
| 1543 | package main; | ||||||||||||||||||||||||||||
| 1544 | |||||||||||||||||||||||||||||
| 1545 | my $results = $unpack->all->validate('string', 'number'); | ||||||||||||||||||||||||||||
| 1546 | |||||||||||||||||||||||||||||
| 1547 | # Exception! (isa Venus::Check::Error) | ||||||||||||||||||||||||||||
| 1548 | |||||||||||||||||||||||||||||
| 1549 | =back | ||||||||||||||||||||||||||||
| 1550 | |||||||||||||||||||||||||||||
| 1551 | =over 4 | ||||||||||||||||||||||||||||
| 1552 | |||||||||||||||||||||||||||||
| 1553 | =item validate example 4 | ||||||||||||||||||||||||||||
| 1554 | |||||||||||||||||||||||||||||
| 1555 | # given: synopsis | ||||||||||||||||||||||||||||
| 1556 | |||||||||||||||||||||||||||||
| 1557 | package main; | ||||||||||||||||||||||||||||
| 1558 | |||||||||||||||||||||||||||||
| 1559 | my $results = $unpack->all->validate('string'); | ||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||
| 1561 | # Exception! (isa Venus::Check::Error) | ||||||||||||||||||||||||||||
| 1562 | |||||||||||||||||||||||||||||
| 1563 | =back | ||||||||||||||||||||||||||||
| 1564 | |||||||||||||||||||||||||||||
| 1565 | =cut | ||||||||||||||||||||||||||||
| 1566 | |||||||||||||||||||||||||||||
| 1567 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 1568 | |||||||||||||||||||||||||||||
| 1569 | Awncorp, C<awncorp@cpan.org> | ||||||||||||||||||||||||||||
| 1570 | |||||||||||||||||||||||||||||
| 1571 | =cut | ||||||||||||||||||||||||||||
| 1572 | |||||||||||||||||||||||||||||
| 1573 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 1574 | |||||||||||||||||||||||||||||
| 1575 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||||||||||||||||||||
| 1576 | |||||||||||||||||||||||||||||
| 1577 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 1578 | the terms of the Apache license version 2.0. | ||||||||||||||||||||||||||||
| 1579 | |||||||||||||||||||||||||||||
| 1580 | =cut | ||||||||||||||||||||||||||||