line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
7
|
|
|
7
|
|
498
|
use 5.006; |
|
7
|
|
|
|
|
18
|
|
2
|
7
|
|
|
7
|
|
27
|
use strict; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
150
|
|
3
|
7
|
|
|
7
|
|
24
|
use warnings; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
456
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Gentoo::Overlay::Exceptions; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '2.001002'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: A custom Exception class for Gentoo which also has warning-style semantics instead of failure |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
7
|
|
|
7
|
|
512
|
use Moo qw( has with ); |
|
7
|
|
|
|
|
10463
|
|
|
7
|
|
|
|
|
45
|
|
14
|
7
|
|
|
7
|
|
5266
|
use Try::Tiny qw( try catch ); |
|
7
|
|
|
|
|
7462
|
|
|
7
|
|
|
|
|
440
|
|
15
|
7
|
|
|
7
|
|
500
|
use Types::Standard qw( HashRef Str ArrayRef ); |
|
7
|
|
|
|
|
53690
|
|
|
7
|
|
|
|
|
50
|
|
16
|
7
|
|
|
7
|
|
5769
|
use Type::Utils qw( declare where as ); |
|
7
|
|
|
|
|
3573
|
|
|
7
|
|
|
|
|
44
|
|
17
|
7
|
|
|
7
|
|
3006
|
use Sub::Exporter::Progressive -setup => { exports => [ 'exception', 'warning', ] }; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
79
|
|
18
|
7
|
|
|
7
|
|
4079
|
use String::Errf qw( errf ); |
|
7
|
|
|
|
|
153963
|
|
|
7
|
|
|
|
|
45
|
|
19
|
7
|
|
|
7
|
|
5265
|
use Const::Fast qw( const ); |
|
7
|
|
|
|
|
6191
|
|
|
7
|
|
|
|
|
38
|
|
20
|
7
|
|
|
7
|
|
3906
|
use namespace::clean -except => [ 'meta', 'import' ]; |
|
7
|
|
|
|
|
60795
|
|
|
7
|
|
|
|
|
64
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
const our $W_SILENT => 'silent'; |
23
|
|
|
|
|
|
|
const our $W_WARNING => 'warning'; |
24
|
|
|
|
|
|
|
const our $W_FATAL => 'fatal'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $WARNINGS_ARE = $W_WARNING; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has ident => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
isa => ( declare as Str, where { length && /\A\S/msx && /\S\z/msx } ), |
31
|
|
|
|
|
|
|
required => 1, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub has_tag { |
35
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $tag ) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
0
|
|
|
0
|
$_ eq $tag && return 1 for $self->tags; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub tags { |
43
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Poor man's uniq: |
46
|
0
|
|
|
|
|
0
|
my %tags = map { ; $_ => 1 } ( @{ $self->_instance_tags } ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
0
|
return wantarray ? keys %tags : ( keys %tags )[0]; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $tag = declare Str, where { length }; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has instance_tags => ( |
54
|
|
|
|
|
|
|
is => 'ro', |
55
|
|
|
|
|
|
|
isa => ArrayRef [$tag], |
56
|
|
|
|
|
|
|
reader => '_instance_tags', |
57
|
|
|
|
|
|
|
init_arg => 'tags', |
58
|
|
|
|
|
|
|
default => sub { [] }, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has 'payload' => ( |
62
|
|
|
|
|
|
|
is => 'ro', |
63
|
|
|
|
|
|
|
isa => HashRef, |
64
|
|
|
|
|
|
|
required => 1, |
65
|
|
|
|
|
|
|
default => sub { {} }, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub as_string { |
69
|
6
|
|
|
6
|
0
|
7372
|
my ($self) = @_; |
70
|
|
|
|
|
|
|
## no critic (RegularExpressions) |
71
|
6
|
|
|
|
|
14
|
return join q{}, $self->message, qq{\n\n }, ( join qq{\n* }, ( split /\n/, $self->stack_trace ) ), qq{\n}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
7
|
|
|
7
|
|
5182
|
use overload ( q{""} => 'as_string' ); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
62
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
## no critic (Subroutines::RequireArgUnpacking) |
77
|
|
|
|
|
|
|
sub exception { |
78
|
4
|
|
|
4
|
0
|
56
|
return __PACKAGE__->throw(@_); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub warning { |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# This code is because warnings::register sucks. |
84
|
|
|
|
|
|
|
# You can't do long-distance warning-changes that behave |
85
|
|
|
|
|
|
|
# similar to exceptions. |
86
|
|
|
|
|
|
|
# |
87
|
|
|
|
|
|
|
# warnings::register can only be toggled in the direcltly |
88
|
|
|
|
|
|
|
# preceeding scope. |
89
|
|
|
|
|
|
|
|
90
|
2
|
50
|
|
2
|
0
|
52
|
return if ( $WARNINGS_ARE eq $W_SILENT ); |
91
|
2
|
100
|
|
|
|
6
|
if ( $WARNINGS_ARE eq $W_WARNING ) { |
92
|
|
|
|
|
|
|
## no critic ( ErrorHandling::RequireCarping ) |
93
|
1
|
|
|
|
|
16
|
return warn __PACKAGE__->new(@_); |
94
|
|
|
|
|
|
|
} |
95
|
1
|
|
|
|
|
8
|
return __PACKAGE__->throw(@_); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub BUILDARGS { |
103
|
6
|
|
|
6
|
0
|
3629
|
my ( undef, @args ) = @_; |
104
|
6
|
50
|
|
|
|
17
|
if ( 1 == scalar @args ) { |
105
|
0
|
0
|
|
|
|
0
|
if ( not ref $args[0] ) { |
106
|
0
|
|
|
|
|
0
|
return { ident => $args[0] }; |
107
|
|
|
|
|
|
|
} |
108
|
0
|
|
|
|
|
0
|
return $args[0]; |
109
|
|
|
|
|
|
|
} |
110
|
6
|
|
|
|
|
128
|
return {@args}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
has 'message_fmt' => ( |
113
|
|
|
|
|
|
|
is => 'ro', |
114
|
|
|
|
|
|
|
isa => Str, |
115
|
|
|
|
|
|
|
lazy => 1, |
116
|
|
|
|
|
|
|
required => 1, |
117
|
|
|
|
|
|
|
init_arg => 'message', |
118
|
|
|
|
|
|
|
default => sub { shift->ident }, |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
with( 'Throwable', 'StackTrace::Auto', ); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub message { |
123
|
6
|
|
|
6
|
0
|
17
|
my ($self) = @_; |
124
|
|
|
|
|
|
|
return try { |
125
|
6
|
|
|
6
|
|
240
|
errf( $self->message_fmt, $self->payload ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
catch { |
128
|
0
|
|
|
0
|
|
|
sprintf '%s (error during formatting)', $self->message_fmt; |
129
|
6
|
|
|
|
|
33
|
},; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
7
|
|
|
7
|
|
2432
|
no Moo; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
55
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=pod |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=encoding UTF-8 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 NAME |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Gentoo::Overlay::Exceptions - A custom Exception class for Gentoo which also has warning-style semantics instead of failure |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 VERSION |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
version 2.001002 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=for Pod::Coverage BUILDARGS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=for Pod::Coverage ident message payload as_string exception warning has_tag tags |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 AUTHOR |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Kent Fredric <kentnl@cpan.org> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
163
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |