| 1 | package Venus::Error; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 39 | ▶ | use 5.018; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 39 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 39 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 39 | ▶ | use Venus::Class 'attr', 'base', 'with'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 39 | base 'Venus::Kind::Utility'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 39 | with 'Venus::Role::Explainable'; | |||||||||||||||||||||||||||
| 13 | 39 | with 'Venus::Role::Stashable'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | use overload ( | ||||||||||||||||||||||||||||
| 16 | '""' => 'explain', | ||||||||||||||||||||||||||||
| 17 | 1 | ▶ | 'eq' => sub{$_[0]->render eq "$_[1]"}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | 'ne' => sub{$_[0]->render ne "$_[1]"}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | 'qr' => sub{qr/@{[quotemeta($_[0]->render)]}/}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 39 | '~~' => 'explain', | |||||||||||||||||||||||||||
| 21 | fallback => 1, | ||||||||||||||||||||||||||||
| 22 | 39 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # ATTRIBUTES | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 39 | attr 'name'; | |||||||||||||||||||||||||||
| 27 | 39 | attr 'context'; | |||||||||||||||||||||||||||
| 28 | 39 | attr 'message'; | |||||||||||||||||||||||||||
| 29 | 39 | attr 'verbose'; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # BUILDERS | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub build_arg { | ||||||||||||||||||||||||||||
| 34 | 1 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_arg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | return { | ||||||||||||||||||||||||||||
| 37 | 1 | message => $data, | |||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub build_self { | ||||||||||||||||||||||||||||
| 42 | 354 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
build_self: called CC=8 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 354 | ▶ | $self->name($data->{name}) if $self->name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 354 | ▶ | $self->context('(None)') if !$self->context; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 354 | ▶ | $self->message('Exception!') if !$self->message; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 354 | ▶ | $self->verbose($ENV{VENUS_ERROR_VERBOSE} // 1) if !exists $data->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ENV{"VENUS_ERROR_VERBOSE"} // 1
MC/DC0%0/1
$ENV{"VENUS_ERROR_VERBOSE"} // 1
$ENV{"VENUS_ERROR_VERBOSE"}
Truth table50%1/2
A
A= $ENV{"VENUS_ERROR_VERBOSE"}
| |||||||||||||||||||||||||||||
| 48 | 354 | ▶ | $self->trace($ENV{VENUS_ERROR_TRACE_OFFSET} // 2) if !@{$self->frames}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ENV{"VENUS_ERROR_TRACE_OFFSET"} // 2
MC/DC0%0/1
$ENV{"VENUS_ERROR_TRACE_OFFSET"} // 2
$ENV{"VENUS_ERROR_TRACE_OFFSET"}
Truth table50%1/2
A
A= $ENV{"VENUS_ERROR_TRACE_OFFSET"}
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 354 | return $self; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # METHODS | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub arguments { | ||||||||||||||||||||||||||||
| 56 | 3 | ▶ | my ($self, $index) = @_; | ||||||||||||||||||||||||||
|
Subroutine
arguments: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 3 | my $captured = $self->captured; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 3 | ▶ | return undef if !$captured; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | my $arguments = $captured->{arguments}; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | return $arguments if !defined $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | return undef if !$arguments; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | return $arguments->[$index]; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub as { | ||||||||||||||||||||||||||||
| 73 | 14 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
as: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 14 | $name = $self->id($name); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 14 | my $method = "as_${name}"; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 14 | ▶ | $self = ref $self ? $self : $self->new; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 14 | ▶ | if (!$self->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 6 | return $self->do('name', $name); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 8 | return $self->$method; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | sub assertion { | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
assertion: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $assertion = $self->SUPER::assertion; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | $assertion->match('string')->format(sub{ | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | (ref $self || $self)->new($_) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 95 | 0 | }); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | return $assertion; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | sub callframe { | ||||||||||||||||||||||||||||
| 101 | 3 | ▶ | my ($self, $index) = @_; | ||||||||||||||||||||||||||
|
Subroutine
callframe: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 3 | my $captured = $self->captured; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | return undef if !$captured; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 2 | my $callframe = $captured->{callframe}; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | ▶ | return $callframe if !defined $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | ▶ | return undef if !$callframe; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | return $callframe->[$index]; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub captured { | ||||||||||||||||||||||||||||
| 117 | 7 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
captured: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 7 | return $self->stash('captured'); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub id { | ||||||||||||||||||||||||||||
| 123 | 2111 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
id: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2111 | ▶ | $name = lc $name =~ s/\W+/_/gr if $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 2111 | return $name; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | sub explain { | ||||||||||||||||||||||||||||
| 131 | 1252 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
explain: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 1252 | ▶ | $self->trace(1, 1) if !@{$self->frames}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 1252 | my $frames = $self->{'$frames'}; | |||||||||||||||||||||||||||
| 136 | 1252 | my $message = $self->render; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 1252 | my @stacktrace = "$message" =~ s/^\s+|\s+$//gr; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 1252 | ▶ | return join "\n", @stacktrace, "" if !$self->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 1252 | ▶ | push @stacktrace, 'Name:', $self->name || '(None)'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->name || '(None)'
MC/DC100%1/1
$self->name || '(None)'
$self->name
Truth table100%2/2
A
A= $self->name
| |||||||||||||||||||||||||||||
| 143 | 1252 | push @stacktrace, 'Type:', ref($self); | |||||||||||||||||||||||||||
| 144 | 1252 | ▶ | push @stacktrace, 'Context:', $self->context || '(None)'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->context || '(None)'
MC/DC0%0/1
$self->context || '(None)'
$self->context
Truth table50%1/2
A
A= $self->context
| |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 39 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 1252 | require Data::Dumper; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 1252 | local $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||
| 151 | 1252 | local $Data::Dumper::Trailingcomma = 0; | |||||||||||||||||||||||||||
| 152 | 1252 | local $Data::Dumper::Purity = 0; | |||||||||||||||||||||||||||
| 153 | 1252 | local $Data::Dumper::Pad = ''; | |||||||||||||||||||||||||||
| 154 | 1252 | local $Data::Dumper::Varname = 'VAR'; | |||||||||||||||||||||||||||
| 155 | 1252 | local $Data::Dumper::Useqq = 0; | |||||||||||||||||||||||||||
| 156 | 1252 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||
| 157 | 1252 | local $Data::Dumper::Freezer = ''; | |||||||||||||||||||||||||||
| 158 | 1252 | local $Data::Dumper::Toaster = ''; | |||||||||||||||||||||||||||
| 159 | 1252 | local $Data::Dumper::Deepcopy = 1; | |||||||||||||||||||||||||||
| 160 | 1252 | local $Data::Dumper::Quotekeys = 0; | |||||||||||||||||||||||||||
| 161 | 1252 | local $Data::Dumper::Bless = 'bless'; | |||||||||||||||||||||||||||
| 162 | 1252 | local $Data::Dumper::Pair = ' => '; | |||||||||||||||||||||||||||
| 163 | 1252 | local $Data::Dumper::Maxdepth = 0; | |||||||||||||||||||||||||||
| 164 | 1252 | local $Data::Dumper::Maxrecurse = 1000; | |||||||||||||||||||||||||||
| 165 | 1252 | local $Data::Dumper::Useperl = 0; | |||||||||||||||||||||||||||
| 166 | 1252 | local $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||
| 167 | 1252 | local $Data::Dumper::Deparse = 1; | |||||||||||||||||||||||||||
| 168 | 1252 | local $Data::Dumper::Sparseseen = 0; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1252 | my $stashed = Data::Dumper->Dump([$self->stash]); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 1252 | $stashed =~ s/^'|'$//g; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 1252 | chomp $stashed; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 1252 | push @stacktrace, 'Stashed:', $stashed; | |||||||||||||||||||||||||||
| 177 | 1252 | ▶ | push @stacktrace, 'Traceback (reverse chronological order):' if @$frames > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 39 | ▶ | use warnings 'once'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 1252 | @stacktrace = (join("\n\n", grep defined, @stacktrace), ''); | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 1252 | ▶ | for (my $i = 1; $i < @$frames; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 27773 | my $pack = $frames->[$i][0]; | |||||||||||||||||||||||||||
| 185 | 27773 | my $file = $frames->[$i][1]; | |||||||||||||||||||||||||||
| 186 | 27773 | my $line = $frames->[$i][2]; | |||||||||||||||||||||||||||
| 187 | 27773 | my $subr = $frames->[$i][3]; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 27773 | push @stacktrace, "$subr\n in $file at line $line"; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 1252 | return join "\n", @stacktrace, ""; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | sub frames { | ||||||||||||||||||||||||||||
| 196 | 1969 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
frames: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 1969 | ▶ | return $self->{'$frames'} //= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"\$frames"} //= []
MC/DC100%1/1
$self->{"\$frames"} //= []
$self->{"\$frames"}
Truth table100%2/2
A
A= $self->{"\$frames"}
| |||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | sub is { | ||||||||||||||||||||||||||||
| 202 | 20 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
is: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 20 | $name = $self->id($name); | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 20 | my $method = "is_${name}"; | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 20 | ▶ | if ($self->name && !$self->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->name and not $self->can($method)
MC/DC50%1/2
$self->name and not $self->can($method)
$self->name
not $self->can($method)
Truth table66%2/3
A and not(B)
A= $self->nameB= not $self->can($method)
| |||||||||||||||||||||||||||||
| 209 | 17 | ▶ | return $self->name eq $name ? true : false; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 3 | ▶ | return (ref $self ? $self: $self->new)->$method ? true : false; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | sub name { | ||||||||||||||||||||||||||||
| 216 | 2072 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 2072 | ▶ | return $self->ITEM('name', $self->id($name) // ()); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->id($name) // ()
MC/DC0%0/2
$self->id($name) // ()
$self->id($name)
()
Truth table66%2/3
A // B
A= $self->id($name)B= ()
| |||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | sub of { | ||||||||||||||||||||||||||||
| 222 | 5 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
of: called CC=6 SCAR=22.8
Pod
documented
| |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 5 | $name = $self->id($name); | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 5 | my $method = "of_${name}"; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 5 | ▶ | if ($self->name && !$self->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->name and not $self->can($method)
MC/DC0%0/2
$self->name and not $self->can($method)
$self->name
not $self->can($method)
Truth table33%1/3
A and not(B)
A= $self->nameB= not $self->can($method)
| |||||||||||||||||||||||||||||
| 229 | 5 | ▶ | return $self->name =~ /$name/ ? true : false; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | ▶ | return (ref $self ? $self: $self->new)->$method ? true : false; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | sub frame { | ||||||||||||||||||||||||||||
| 236 | 2 | ▶ | my ($self, $index) = @_; | ||||||||||||||||||||||||||
|
Subroutine
frame: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 2 | my $frames = $self->frames; | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 2 | ▶ | $index //= 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$index //= 0
MC/DC100%1/1
$index //= 0
$index
Truth table100%2/2
A
A= $index
| |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | return { | ||||||||||||||||||||||||||||
| 243 | 2 | package => $frames->[$index][0], | |||||||||||||||||||||||||||
| 244 | filename => $frames->[$index][1], | ||||||||||||||||||||||||||||
| 245 | line => $frames->[$index][2], | ||||||||||||||||||||||||||||
| 246 | subroutine => $frames->[$index][3], | ||||||||||||||||||||||||||||
| 247 | hasargs => $frames->[$index][4], | ||||||||||||||||||||||||||||
| 248 | wantarray => $frames->[$index][5], | ||||||||||||||||||||||||||||
| 249 | evaltext => $frames->[$index][6], | ||||||||||||||||||||||||||||
| 250 | is_require => $frames->[$index][7], | ||||||||||||||||||||||||||||
| 251 | hints => $frames->[$index][8], | ||||||||||||||||||||||||||||
| 252 | bitmask => $frames->[$index][9], | ||||||||||||||||||||||||||||
| 253 | hinthash => $frames->[$index][10], | ||||||||||||||||||||||||||||
| 254 | }; | ||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | sub render { | ||||||||||||||||||||||||||||
| 258 | 1397 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
render: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 1397 | my $message = $self->message; | |||||||||||||||||||||||||||
| 261 | 1397 | my $stashed = $self->stash; | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 1397 | ▶ | while (my($key, $value) = each(%$stashed)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 4083 | my $token = quotemeta $key; | |||||||||||||||||||||||||||
| 265 | 4083 | $message =~ s/\{\{\s*$token\s*\}\}/$value/g; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 1397 | return $message; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | sub throw { | ||||||||||||||||||||||||||||
| 272 | 358 | ▶ | my ($self, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
throw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 358 | ▶ | $self = $self->new(@args) if !ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 358 | die $self; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | sub trace { | ||||||||||||||||||||||||||||
| 280 | 357 | ▶ | my ($self, $offset, $limit) = @_; | ||||||||||||||||||||||||||
|
Subroutine
trace: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 357 | my $frames = $self->frames; | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 357 | @$frames = (); | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 357 | ▶ | for (my $i = $offset // 1; my @caller = caller($i); $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$offset // 1
MC/DC100%1/1
$offset // 1
$offset
Truth table100%2/2
A
A= $offset
| |||||||||||||||||||||||||||||
| 287 | 8044 | push @$frames, [@caller]; | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 8044 | ▶ | last if defined $limit && $i + 1 == $offset + $limit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $limit and $i + 1 == $offset + $limit
MC/DC100%2/2
defined $limit and $i + 1 == $offset + $limit
defined $limit
$i + 1 == $offset + $limit
Truth table100%3/3
A and B
A= defined $limitB= $i + 1 == $offset + $limit
| |||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 357 | return $self; | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 39 | 1; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | =head1 NAME | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | Venus::Error - Error Class | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =cut | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | =head1 ABSTRACT | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | Error Class for Perl 5 | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =cut | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | package main; | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | use Venus::Error; | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | my $error = Venus::Error->new; | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | # $error->throw; | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | =cut | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | This package represents a context-aware error (exception object). The default | ||||||||||||||||||||||||||||
| 326 | for error verbosity can be controlled via the C<VENUS_ERROR_VERBOSE> | ||||||||||||||||||||||||||||
| 327 | environment variable, e.g. a setting of C<0> disables stack traces. The default | ||||||||||||||||||||||||||||
| 328 | trace-offset can be controlled via the C<VENUS_ERROR_TRACE_OFFSET> environment | ||||||||||||||||||||||||||||
| 329 | variable, e.g. a setting of C<0> indicates no offset. | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | =cut | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | This package has the following attributes: | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | =cut | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | =head2 name | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | name(Str) | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | This attribute is read-write, accepts C<(Str)> values, and is optional. | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | =cut | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | =head2 context | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | context(Str) | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | This attribute is read-write, accepts C<(Str)> values, is optional, and defaults to C<'(None)'>. | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | =cut | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | =head2 message | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | message(Str) | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | This attribute is read-write, accepts C<(Str)> values, is optional, and defaults to C<'Exception!'>. | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | =cut | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | =head2 verbose | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | verbose(Int) | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | This attribute is read-write, accepts C<(Int)> values, is optional, and defaults to C<1>. | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | =cut | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | =head1 INHERITS | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | This package inherits behaviors from: | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | L<Venus::Kind::Utility> | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | =cut | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | =head1 INTEGRATES | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | This package integrates behaviors from: | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | L<Venus::Role::Explainable> | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | L<Venus::Role::Stashable> | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | =cut | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | =head1 METHODS | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | This package provides the following methods: | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | =cut | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | =head2 arguments | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | arguments(number $index) (any) | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | The arguments method returns the stashed arguments under L</captured>, or a | ||||||||||||||||||||||||||||
| 400 | specific argument if an index is provided. | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | I<Since C<2.55>> | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | =over 4 | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | =item arguments example 1 | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | # given: synopsis | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | my $arguments = $error->arguments; | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | # undef | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | =back | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | =over 4 | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | =item arguments example 2 | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | package main; | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | use Venus::Throw; | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | my $error = Venus::Throw->new->capture(1..4)->catch('error'); | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | my $arguments = $error->arguments; | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | # [1..4] | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | =back | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | =over 4 | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | =item arguments example 3 | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | package main; | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | use Venus::Throw; | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | my $error = Venus::Throw->new->capture(1..4)->catch('error'); | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | my $arguments = $error->arguments(0); | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | # 1 | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | =back | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | =cut | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | =head2 as | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | as(string $name) (Venus::Error) | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | The as method returns an error object using the return value(s) of the "as" | ||||||||||||||||||||||||||||
| 455 | method specified, which should be defined as C<"as_${name}">, which will be | ||||||||||||||||||||||||||||
| 456 | called automatically by this method. If no C<"as_${name}"> method exists, this | ||||||||||||||||||||||||||||
| 457 | method will set the L</name> attribute to the value provided. | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | I<Since C<1.02>> | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | =over 4 | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | =item as example 1 | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | package System::Error; | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | use Venus::Class; | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | sub as_auth_error { | ||||||||||||||||||||||||||||
| 472 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | return $self->do('message', 'auth_error'); | ||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | sub as_role_error { | ||||||||||||||||||||||||||||
| 478 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | return $self->do('message', 'role_error'); | ||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | sub is_auth_error { | ||||||||||||||||||||||||||||
| 484 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | return $self->message eq 'auth_error'; | ||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | sub is_role_error { | ||||||||||||||||||||||||||||
| 490 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | return $self->message eq 'role_error'; | ||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | package main; | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | my $error = System::Error->new->as('auth_error'); | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | $error->throw; | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | # Exception! (isa Venus::Error) | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | =back | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | =over 4 | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | =item as example 2 | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | package System::Error; | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | use Venus::Class; | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | sub as_auth_error { | ||||||||||||||||||||||||||||
| 516 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | return $self->do('message', 'auth_error'); | ||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | sub as_role_error { | ||||||||||||||||||||||||||||
| 522 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | return $self->do('message', 'role_error'); | ||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | sub is_auth_error { | ||||||||||||||||||||||||||||
| 528 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | return $self->message eq 'auth_error'; | ||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | sub is_role_error { | ||||||||||||||||||||||||||||
| 534 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | return $self->message eq 'role_error'; | ||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | package main; | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | my $error = System::Error->new->as('role_error'); | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | $error->throw; | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | # Exception! (isa Venus::Error) | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | =back | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | =over 4 | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | =item as example 3 | ||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | package Virtual::Error; | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | use Venus::Class; | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | package main; | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | my $error = Virtual::Error->new->as('on_save_error'); | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | $error->throw; | ||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | # name is "on_save_error" | ||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | # Exception! (isa Venus::Error) | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | =back | ||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | =over 4 | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | =item as example 4 | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | package Virtual::Error; | ||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | use Venus::Class; | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | package main; | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | my $error = Virtual::Error->new->as('on.SAVE.error'); | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | $error->throw; | ||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | # name is "on_save_error" | ||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | # Exception! (isa Venus::Error) | ||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | =back | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | =cut | ||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | =head2 callframe | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | callframe(number $index) (any) | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | The callframe method returns the stashed callframe under L</captured>, or a | ||||||||||||||||||||||||||||
| 600 | specific argument if an index is provided. | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | I<Since C<2.55>> | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | =over 4 | ||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | =item callframe example 1 | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | # given: synopsis | ||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||
| 610 | my $callframe = $error->callframe; | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | # undef | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | =back | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | =over 4 | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | =item callframe example 2 | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | package main; | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | use Venus::Throw; | ||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | my $error = Venus::Throw->new->do('frame', 0)->capture->catch('error'); | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | my $callframe = $error->callframe; | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | # [...] | ||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | =back | ||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | =over 4 | ||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | =item callframe example 3 | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | package main; | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | use Venus::Throw; | ||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||
| 640 | my $error = Venus::Throw->new->do('frame', 0)->capture->catch('error'); | ||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | my $package = $error->callframe(0); | ||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||
| 644 | # 'main' | ||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||
| 646 | =back | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | =cut | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | =head2 captured | ||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | captured() (hashref) | ||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||
| 654 | The captured method returns the value stashed as C<"captured">. | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | I<Since C<2.55>> | ||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||
| 658 | =over 4 | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | =item captured example 1 | ||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||
| 662 | # given: synopsis | ||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||
| 664 | my $captured = $error->captured; | ||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | # undef | ||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | =back | ||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||
| 670 | =cut | ||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | =head2 explain | ||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | explain() (string) | ||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||
| 676 | The explain method returns the error message and is used in stringification | ||||||||||||||||||||||||||||
| 677 | operations. | ||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | I<Since C<0.01>> | ||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | =over 4 | ||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | =item explain example 1 | ||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | # given: synopsis; | ||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | my $explain = $error->explain; | ||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | # "Exception! in ... | ||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | =back | ||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | =cut | ||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||
| 695 | =head2 frame | ||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||
| 697 | frame(number $index) (hashref) | ||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||
| 699 | The frame method returns the data from C<caller> on the frames captured, and | ||||||||||||||||||||||||||||
| 700 | returns a hashref where the keys map to the keys described by | ||||||||||||||||||||||||||||
| 701 | L<perlfunc/caller>. | ||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||
| 703 | I<Since C<1.11>> | ||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||
| 705 | =over 4 | ||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||
| 707 | =item frame example 1 | ||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||
| 709 | # given: synopsis; | ||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||
| 711 | my $frame = $error->frame; | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | # { | ||||||||||||||||||||||||||||
| 714 | # 'bitmask' => '...', | ||||||||||||||||||||||||||||
| 715 | # 'evaltext' => '...', | ||||||||||||||||||||||||||||
| 716 | # 'filename' => '...', | ||||||||||||||||||||||||||||
| 717 | # 'hasargs' => '...', | ||||||||||||||||||||||||||||
| 718 | # 'hinthash' => '...', | ||||||||||||||||||||||||||||
| 719 | # 'hints' => '...', | ||||||||||||||||||||||||||||
| 720 | # 'is_require' => '...', | ||||||||||||||||||||||||||||
| 721 | # 'line' => '...', | ||||||||||||||||||||||||||||
| 722 | # 'package' => '...', | ||||||||||||||||||||||||||||
| 723 | # 'subroutine' => '...', | ||||||||||||||||||||||||||||
| 724 | # 'wantarray' => '...', | ||||||||||||||||||||||||||||
| 725 | # } | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | =back | ||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | =over 4 | ||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||
| 731 | =item frame example 2 | ||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||
| 733 | # given: synopsis; | ||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||
| 735 | my $frame = $error->frame(1); | ||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | # { | ||||||||||||||||||||||||||||
| 738 | # 'bitmask' => '...', | ||||||||||||||||||||||||||||
| 739 | # 'evaltext' => '...', | ||||||||||||||||||||||||||||
| 740 | # 'filename' => '...', | ||||||||||||||||||||||||||||
| 741 | # 'hasargs' => '...', | ||||||||||||||||||||||||||||
| 742 | # 'hinthash' => '...', | ||||||||||||||||||||||||||||
| 743 | # 'hints' => '...', | ||||||||||||||||||||||||||||
| 744 | # 'is_require' => '...', | ||||||||||||||||||||||||||||
| 745 | # 'line' => '...', | ||||||||||||||||||||||||||||
| 746 | # 'package' => '...', | ||||||||||||||||||||||||||||
| 747 | # 'subroutine' => '...', | ||||||||||||||||||||||||||||
| 748 | # 'wantarray' => '...', | ||||||||||||||||||||||||||||
| 749 | # } | ||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | =back | ||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||
| 753 | =cut | ||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||
| 755 | =head2 frames | ||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||
| 757 | frames() (arrayref) | ||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||
| 759 | The frames method returns the compiled and stashed stack trace data. | ||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||
| 761 | I<Since C<0.01>> | ||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | =over 4 | ||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||
| 765 | =item frames example 1 | ||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||
| 767 | # given: synopsis; | ||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||
| 769 | my $frames = $error->frames; | ||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||
| 771 | # [ | ||||||||||||||||||||||||||||
| 772 | # ... | ||||||||||||||||||||||||||||
| 773 | # [ | ||||||||||||||||||||||||||||
| 774 | # "main", | ||||||||||||||||||||||||||||
| 775 | # "t/Venus_Error.t", | ||||||||||||||||||||||||||||
| 776 | # ... | ||||||||||||||||||||||||||||
| 777 | # ], | ||||||||||||||||||||||||||||
| 778 | # ] | ||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||
| 780 | =back | ||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||
| 782 | =cut | ||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||
| 784 | =head2 is | ||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||
| 786 | is(string $name) (boolean) | ||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||
| 788 | The is method returns truthy or falsy based on the return value(s) of the "is" | ||||||||||||||||||||||||||||
| 789 | method specified, which should be defined as C<"is_${name}">, which will be | ||||||||||||||||||||||||||||
| 790 | called automatically by this method. If no C<"is_${name}"> method exists, this | ||||||||||||||||||||||||||||
| 791 | method will check if the L</name> attribute is equal to the value provided. | ||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||
| 793 | I<Since C<1.02>> | ||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||
| 795 | =over 4 | ||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||
| 797 | =item is example 1 | ||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||
| 799 | package System::Error; | ||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||
| 801 | use Venus::Class; | ||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||
| 803 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||
| 805 | sub as_auth_error { | ||||||||||||||||||||||||||||
| 806 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||
| 808 | return $self->do('message', 'auth_error'); | ||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||
| 811 | sub as_role_error { | ||||||||||||||||||||||||||||
| 812 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||
| 814 | return $self->do('message', 'role_error'); | ||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||
| 817 | sub is_auth_error { | ||||||||||||||||||||||||||||
| 818 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||
| 820 | return $self->message eq 'auth_error'; | ||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||
| 823 | sub is_role_error { | ||||||||||||||||||||||||||||
| 824 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||
| 826 | return $self->message eq 'role_error'; | ||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||
| 829 | package main; | ||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||
| 831 | my $is = System::Error->new->as('auth_error')->is('auth_error'); | ||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||
| 833 | # 1 | ||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||
| 835 | =back | ||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||
| 837 | =over 4 | ||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||
| 839 | =item is example 2 | ||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||
| 841 | package System::Error; | ||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||
| 843 | use Venus::Class; | ||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||
| 845 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||
| 847 | sub as_auth_error { | ||||||||||||||||||||||||||||
| 848 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | return $self->do('message', 'auth_error'); | ||||||||||||||||||||||||||||
| 851 | } | ||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||
| 853 | sub as_role_error { | ||||||||||||||||||||||||||||
| 854 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||
| 856 | return $self->do('message', 'role_error'); | ||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||
| 859 | sub is_auth_error { | ||||||||||||||||||||||||||||
| 860 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||
| 862 | return $self->message eq 'auth_error'; | ||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||
| 865 | sub is_role_error { | ||||||||||||||||||||||||||||
| 866 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||
| 868 | return $self->message eq 'role_error'; | ||||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||
| 871 | package main; | ||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||
| 873 | my $is = System::Error->as('auth_error')->is('auth_error'); | ||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||
| 875 | # 1 | ||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||
| 877 | =back | ||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||
| 879 | =over 4 | ||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||
| 881 | =item is example 3 | ||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||
| 883 | package System::Error; | ||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||
| 885 | use Venus::Class; | ||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||
| 887 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||
| 889 | sub as_auth_error { | ||||||||||||||||||||||||||||
| 890 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||
| 892 | return $self->do('message', 'auth_error'); | ||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||
| 895 | sub as_role_error { | ||||||||||||||||||||||||||||
| 896 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||
| 898 | return $self->do('message', 'role_error'); | ||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||
| 901 | sub is_auth_error { | ||||||||||||||||||||||||||||
| 902 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||
| 904 | return $self->message eq 'auth_error'; | ||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||
| 907 | sub is_role_error { | ||||||||||||||||||||||||||||
| 908 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||
| 910 | return $self->message eq 'role_error'; | ||||||||||||||||||||||||||||
| 911 | } | ||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||
| 913 | package main; | ||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||
| 915 | my $is = System::Error->as('auth_error')->is('role_error'); | ||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||
| 917 | # 0 | ||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||
| 919 | =back | ||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||
| 921 | =over 4 | ||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||
| 923 | =item is example 4 | ||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||
| 925 | package Virtual::Error; | ||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||
| 927 | use Venus::Class; | ||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||
| 929 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||
| 931 | package main; | ||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||
| 933 | my $is = Virtual::Error->new->as('on_save_error')->is('on_save_error'); | ||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||
| 935 | # 1 | ||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | =back | ||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||
| 939 | =over 4 | ||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||
| 941 | =item is example 5 | ||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||
| 943 | package Virtual::Error; | ||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||
| 945 | use Venus::Class; | ||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||
| 947 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||
| 949 | package main; | ||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||
| 951 | my $is = Virtual::Error->new->as('on.SAVE.error')->is('on_save_error'); | ||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||
| 953 | # 1 | ||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||
| 955 | =back | ||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||
| 957 | =cut | ||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||
| 959 | =head2 of | ||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||
| 961 | of(string $name) (boolean) | ||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||
| 963 | The of method returns truthy or falsy based on the return value(s) of the "of" | ||||||||||||||||||||||||||||
| 964 | method specified, which should be defined as C<"of_${name}">, which will be | ||||||||||||||||||||||||||||
| 965 | called automatically by this method. If no C<"of_${name}"> method exists, this | ||||||||||||||||||||||||||||
| 966 | method will check if the L</name> attribute contains the value provided. | ||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||
| 968 | I<Since C<1.11>> | ||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||
| 970 | =over 4 | ||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||
| 972 | =item of example 1 | ||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||
| 974 | package System::Error; | ||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||
| 976 | use Venus::Class; | ||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||
| 978 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||
| 980 | sub as_auth_error { | ||||||||||||||||||||||||||||
| 981 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||
| 983 | return $self->do('name', 'auth_error'); | ||||||||||||||||||||||||||||
| 984 | } | ||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||
| 986 | sub as_role_error { | ||||||||||||||||||||||||||||
| 987 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||
| 989 | return $self->do('name', 'role_error'); | ||||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||
| 992 | sub is_auth_error { | ||||||||||||||||||||||||||||
| 993 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||
| 995 | return $self->name eq 'auth_error'; | ||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||
| 998 | sub is_role_error { | ||||||||||||||||||||||||||||
| 999 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||
| 1001 | return $self->name eq 'role_error'; | ||||||||||||||||||||||||||||
| 1002 | } | ||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||
| 1004 | package main; | ||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||
| 1006 | my $of = System::Error->as('auth_error')->of('role'); | ||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||
| 1008 | # 0 | ||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||
| 1010 | =back | ||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||
| 1012 | =over 4 | ||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||
| 1014 | =item of example 2 | ||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||
| 1016 | package System::Error; | ||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||
| 1018 | use Venus::Class; | ||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||
| 1020 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||
| 1022 | sub as_auth_error { | ||||||||||||||||||||||||||||
| 1023 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||
| 1025 | return $self->do('name', 'auth_error'); | ||||||||||||||||||||||||||||
| 1026 | } | ||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||
| 1028 | sub as_role_error { | ||||||||||||||||||||||||||||
| 1029 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||
| 1031 | return $self->do('name', 'role_error'); | ||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||
| 1034 | sub is_auth_error { | ||||||||||||||||||||||||||||
| 1035 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||
| 1037 | return $self->name eq 'auth_error'; | ||||||||||||||||||||||||||||
| 1038 | } | ||||||||||||||||||||||||||||
| 1039 | |||||||||||||||||||||||||||||
| 1040 | sub is_role_error { | ||||||||||||||||||||||||||||
| 1041 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||
| 1043 | return $self->name eq 'role_error'; | ||||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||
| 1046 | package main; | ||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||
| 1048 | my $of = System::Error->as('auth_error')->of('auth'); | ||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||
| 1050 | # 1 | ||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||
| 1052 | =back | ||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||
| 1054 | =over 4 | ||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||
| 1056 | =item of example 3 | ||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||
| 1058 | package System::Error; | ||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||
| 1060 | use Venus::Class; | ||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||
| 1062 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||
| 1064 | sub as_auth_error { | ||||||||||||||||||||||||||||
| 1065 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||
| 1067 | return $self->do('name', 'auth_error'); | ||||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||
| 1069 | |||||||||||||||||||||||||||||
| 1070 | sub as_role_error { | ||||||||||||||||||||||||||||
| 1071 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||
| 1073 | return $self->do('name', 'role_error'); | ||||||||||||||||||||||||||||
| 1074 | } | ||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||
| 1076 | sub is_auth_error { | ||||||||||||||||||||||||||||
| 1077 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||
| 1079 | return $self->name eq 'auth_error'; | ||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||
| 1082 | sub is_role_error { | ||||||||||||||||||||||||||||
| 1083 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 1084 | |||||||||||||||||||||||||||||
| 1085 | return $self->name eq 'role_error'; | ||||||||||||||||||||||||||||
| 1086 | } | ||||||||||||||||||||||||||||
| 1087 | |||||||||||||||||||||||||||||
| 1088 | package main; | ||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||
| 1090 | my $of = System::Error->as('auth_error')->of('role_error'); | ||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||
| 1092 | # 0 | ||||||||||||||||||||||||||||
| 1093 | |||||||||||||||||||||||||||||
| 1094 | =back | ||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||
| 1096 | =over 4 | ||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||
| 1098 | =item of example 4 | ||||||||||||||||||||||||||||
| 1099 | |||||||||||||||||||||||||||||
| 1100 | package Virtual::Error; | ||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||
| 1102 | use Venus::Class; | ||||||||||||||||||||||||||||
| 1103 | |||||||||||||||||||||||||||||
| 1104 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 1105 | |||||||||||||||||||||||||||||
| 1106 | package main; | ||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||
| 1108 | my $of = Virtual::Error->new->as('on_save_error')->of('on.save'); | ||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||
| 1110 | # 1 | ||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||
| 1112 | =back | ||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||
| 1114 | =over 4 | ||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||
| 1116 | =item of example 5 | ||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||
| 1118 | package Virtual::Error; | ||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||
| 1120 | use Venus::Class; | ||||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||
| 1122 | base 'Venus::Error'; | ||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||
| 1124 | package main; | ||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||
| 1126 | my $of = Virtual::Error->new->as('on.SAVE.error')->of('on.save'); | ||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||
| 1128 | # 1 | ||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||
| 1130 | =back | ||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||
| 1132 | =cut | ||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||
| 1134 | =head2 render | ||||||||||||||||||||||||||||
| 1135 | |||||||||||||||||||||||||||||
| 1136 | render() (string) | ||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||
| 1138 | The render method replaces tokens in the message with values from the stash and | ||||||||||||||||||||||||||||
| 1139 | returns the formatted string. The token style and formatting operation is | ||||||||||||||||||||||||||||
| 1140 | equivalent to the L<Venus::String/render> operation. | ||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||
| 1142 | I<Since C<3.30>> | ||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||
| 1144 | =over 4 | ||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||
| 1146 | =item render example 1 | ||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||
| 1148 | # given: synopsis | ||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||
| 1150 | package main; | ||||||||||||||||||||||||||||
| 1151 | |||||||||||||||||||||||||||||
| 1152 | $error->message('Signal received: {{signal}}'); | ||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||
| 1154 | $error->stash(signal => 'SIGKILL'); | ||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||
| 1156 | my $render = $error->render; | ||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||
| 1158 | # "Signal received: SIGKILL" | ||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||
| 1160 | =back | ||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||
| 1162 | =cut | ||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||
| 1164 | =head2 throw | ||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||
| 1166 | throw(any @data) (Venus::Error) | ||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||
| 1168 | The throw method throws an error if the invocant is an object, or creates an | ||||||||||||||||||||||||||||
| 1169 | error object using the arguments provided and throws the created object. | ||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||
| 1171 | I<Since C<0.01>> | ||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||
| 1173 | =over 4 | ||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||
| 1175 | =item throw example 1 | ||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||
| 1177 | # given: synopsis; | ||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||
| 1179 | my $throw = $error->throw; | ||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||
| 1181 | # bless({ ... }, 'Venus::Error') | ||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||
| 1183 | =back | ||||||||||||||||||||||||||||
| 1184 | |||||||||||||||||||||||||||||
| 1185 | =cut | ||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||
| 1187 | =head2 trace | ||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||
| 1189 | trace(number $offset, number $limit) (Venus::Error) | ||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||
| 1191 | The trace method compiles a stack trace and returns the object. By default it | ||||||||||||||||||||||||||||
| 1192 | skips the first frame. | ||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||
| 1194 | I<Since C<0.01>> | ||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||
| 1196 | =over 4 | ||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||
| 1198 | =item trace example 1 | ||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||
| 1200 | # given: synopsis; | ||||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||
| 1202 | my $trace = $error->trace; | ||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||
| 1204 | # bless({ ... }, 'Venus::Error') | ||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||
| 1206 | =back | ||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||
| 1208 | =over 4 | ||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||
| 1210 | =item trace example 2 | ||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||
| 1212 | # given: synopsis; | ||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||
| 1214 | my $trace = $error->trace(0, 1); | ||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||
| 1216 | # bless({ ... }, 'Venus::Error') | ||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||
| 1218 | =back | ||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||
| 1220 | =over 4 | ||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||
| 1222 | =item trace example 3 | ||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||
| 1224 | # given: synopsis; | ||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||
| 1226 | my $trace = $error->trace(0, 2); | ||||||||||||||||||||||||||||
| 1227 | |||||||||||||||||||||||||||||
| 1228 | # bless({ ... }, 'Venus::Error') | ||||||||||||||||||||||||||||
| 1229 | |||||||||||||||||||||||||||||
| 1230 | =back | ||||||||||||||||||||||||||||
| 1231 | |||||||||||||||||||||||||||||
| 1232 | =cut | ||||||||||||||||||||||||||||
| 1233 | |||||||||||||||||||||||||||||
| 1234 | =head1 OPERATORS | ||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||
| 1236 | This package overloads the following operators: | ||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||
| 1238 | =cut | ||||||||||||||||||||||||||||
| 1239 | |||||||||||||||||||||||||||||
| 1240 | =over 4 | ||||||||||||||||||||||||||||
| 1241 | |||||||||||||||||||||||||||||
| 1242 | =item operation: C<("")> | ||||||||||||||||||||||||||||
| 1243 | |||||||||||||||||||||||||||||
| 1244 | This package overloads the C<""> operator. | ||||||||||||||||||||||||||||
| 1245 | |||||||||||||||||||||||||||||
| 1246 | B<example 1> | ||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||
| 1248 | # given: synopsis; | ||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||
| 1250 | my $result = "$error"; | ||||||||||||||||||||||||||||
| 1251 | |||||||||||||||||||||||||||||
| 1252 | # "Exception!" | ||||||||||||||||||||||||||||
| 1253 | |||||||||||||||||||||||||||||
| 1254 | =back | ||||||||||||||||||||||||||||
| 1255 | |||||||||||||||||||||||||||||
| 1256 | =over 4 | ||||||||||||||||||||||||||||
| 1257 | |||||||||||||||||||||||||||||
| 1258 | =item operation: C<(eq)> | ||||||||||||||||||||||||||||
| 1259 | |||||||||||||||||||||||||||||
| 1260 | This package overloads the C<eq> operator. | ||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||
| 1262 | B<example 1> | ||||||||||||||||||||||||||||
| 1263 | |||||||||||||||||||||||||||||
| 1264 | # given: synopsis; | ||||||||||||||||||||||||||||
| 1265 | |||||||||||||||||||||||||||||
| 1266 | my $result = $error eq 'Exception!'; | ||||||||||||||||||||||||||||
| 1267 | |||||||||||||||||||||||||||||
| 1268 | # 1 | ||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||
| 1270 | =back | ||||||||||||||||||||||||||||
| 1271 | |||||||||||||||||||||||||||||
| 1272 | =over 4 | ||||||||||||||||||||||||||||
| 1273 | |||||||||||||||||||||||||||||
| 1274 | =item operation: C<(ne)> | ||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||
| 1276 | This package overloads the C<ne> operator. | ||||||||||||||||||||||||||||
| 1277 | |||||||||||||||||||||||||||||
| 1278 | B<example 1> | ||||||||||||||||||||||||||||
| 1279 | |||||||||||||||||||||||||||||
| 1280 | # given: synopsis; | ||||||||||||||||||||||||||||
| 1281 | |||||||||||||||||||||||||||||
| 1282 | my $result = $error ne 'exception!'; | ||||||||||||||||||||||||||||
| 1283 | |||||||||||||||||||||||||||||
| 1284 | # 1 | ||||||||||||||||||||||||||||
| 1285 | |||||||||||||||||||||||||||||
| 1286 | =back | ||||||||||||||||||||||||||||
| 1287 | |||||||||||||||||||||||||||||
| 1288 | =over 4 | ||||||||||||||||||||||||||||
| 1289 | |||||||||||||||||||||||||||||
| 1290 | =item operation: C<(qr)> | ||||||||||||||||||||||||||||
| 1291 | |||||||||||||||||||||||||||||
| 1292 | This package overloads the C<qr> operator. | ||||||||||||||||||||||||||||
| 1293 | |||||||||||||||||||||||||||||
| 1294 | B<example 1> | ||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||
| 1296 | # given: synopsis; | ||||||||||||||||||||||||||||
| 1297 | |||||||||||||||||||||||||||||
| 1298 | my $test = 'Exception!' =~ qr/$error/; | ||||||||||||||||||||||||||||
| 1299 | |||||||||||||||||||||||||||||
| 1300 | # 1 | ||||||||||||||||||||||||||||
| 1301 | |||||||||||||||||||||||||||||
| 1302 | =back | ||||||||||||||||||||||||||||
| 1303 | |||||||||||||||||||||||||||||
| 1304 | =over 4 | ||||||||||||||||||||||||||||
| 1305 | |||||||||||||||||||||||||||||
| 1306 | =item operation: C<(~~)> | ||||||||||||||||||||||||||||
| 1307 | |||||||||||||||||||||||||||||
| 1308 | This package overloads the C<~~> operator. | ||||||||||||||||||||||||||||
| 1309 | |||||||||||||||||||||||||||||
| 1310 | B<example 1> | ||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||
| 1312 | # given: synopsis; | ||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||
| 1314 | my $result = $error ~~ 'Exception!'; | ||||||||||||||||||||||||||||
| 1315 | |||||||||||||||||||||||||||||
| 1316 | # 1 | ||||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||
| 1318 | =back | ||||||||||||||||||||||||||||
| 1319 | |||||||||||||||||||||||||||||
| 1320 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||
| 1322 | Awncorp, C<awncorp@cpan.org> | ||||||||||||||||||||||||||||
| 1323 | |||||||||||||||||||||||||||||
| 1324 | =cut | ||||||||||||||||||||||||||||
| 1325 | |||||||||||||||||||||||||||||
| 1326 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 1327 | |||||||||||||||||||||||||||||
| 1328 | Copyright (C) 2000, Awncorp, C<awncorp@cpan.org>. | ||||||||||||||||||||||||||||
| 1329 | |||||||||||||||||||||||||||||
| 1330 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 1331 | the terms of the Apache license version 2.0. | ||||||||||||||||||||||||||||
| 1332 | |||||||||||||||||||||||||||||
| 1333 | =cut | ||||||||||||||||||||||||||||