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