Overlay/Exceptions.pm

filter: Statementstmt 81.4% 66 / 81 Branchbran 35.7% 5 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 21 / 27 Podpod 0.0% 0 / 7 totaltotal 69.4% 93 / 134 CC 10 SCAR 11.0
CC
10
Cov
73%
has_tag
12.0
tags
6.0
BUILDARGS
4.9
CRAP 3.0
« Overlay/Types.pm ↑ Summary Overlay/Package.pm »
1 7 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Gentoo::Overlay::Exceptions;
6  
7 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 7 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 7 ▶use Moo qw( has with );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use Try::Tiny qw( try catch );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use Types::Standard qw( HashRef Str ArrayRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use Type::Utils qw( declare where as );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use Sub::Exporter::Progressive -setup => { exports => [ 'exception', 'warning', ] };
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use String::Errf qw( errf );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use Const::Fast qw( const );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use namespace::clean -except => [ 'meta', 'import' ];
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 7 const our $W_SILENT => 'silent';
23 7 const our $W_WARNING => 'warning';
24 7 const our $W_FATAL => 'fatal';
25  
26 7 our $WARNINGS_ARE = $W_WARNING;
27  
28 has ident => (
29 is => 'ro',
30 6 ▶ isa => ( declare as Str, where { length && /\A\S/msx && /\S\z/msx } ),
Subroutine __ANON__: called CC=3 SCAR=13.1
Branch: 1 branch
BranchTrueFalseTotal
length $_ and /\A\S/msx and /\S\z/msx 6 0 6
Condition33%1/3
length $_ and /\A\S/msx
!ll&&!rl&&r
006
MC/DC0%0/2
length $_ and /\A\S/msx
length $_ /\A\S/msx
Truth table33%1/3
A and B
A= length $_B= /\A\S/msx
ABresult
0X0
100
111
31 required => 1,
32 );
33  
34 0 ▶sub has_tag {
Subroutine has_tag: not called CC=3 SCAR=24.8
Pod undocumented
35 0 my ( $self, $tag ) = @_;
36  
37 0 ▶ $_ eq $tag && return 1 for $self->tags;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $tag and return 1 0 0 0
38  
39 0 return;
40 }
41  
42 0 ▶sub tags {
Subroutine tags: not called CC=2 SCAR=17.9
Pod undocumented
43 0 my ($self) = @_;
44  
45 # Poor man's uniq:
46 0 my %tags = map { ; $_ => 1 } ( @{ $self->_instance_tags } );
47  
48 0 ▶ return wantarray ? keys %tags : ( keys %tags )[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
49 }
50  
51 0 ▶my $tag = declare Str, where { length };
Subroutine __ANON__: not called CC=1 SCAR=1.2
52  
53 has instance_tags => (
54 is => 'ro',
55 isa => ArrayRef [$tag],
56 reader => '_instance_tags',
57 init_arg => 'tags',
58 6 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
59 7 );
60  
61 has 'payload' => (
62 is => 'ro',
63 isa => HashRef,
64 required => 1,
65 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 7 );
67  
68 6 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
69 6 my ($self) = @_;
70 ## no critic (RegularExpressions)
71 6 return join q{}, $self->message, qq{\n\n }, ( join qq{\n* }, ( split /\n/, $self->stack_trace ) ), qq{\n};
72 }
73  
74 7 ▶use overload ( q{""} => 'as_string' );
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 ## no critic (Subroutines::RequireArgUnpacking)
77 4 ▶sub exception {
Subroutine exception: called CC=1 SCAR=0.0
Pod undocumented
78 4 return __PACKAGE__->throw(@_);
79 }
80  
81 2 ▶sub warning {
Subroutine warning: called CC=3 SCAR=11.0
Pod undocumented
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 ▶ return if ( $WARNINGS_ARE eq $W_SILENT );
Branch: 1 branch
BranchTrueFalseTotal
if $Gentoo::Overlay::Exceptions::WARNINGS_ARE eq $Gentoo::Overlay::Exceptions::W_SILENT 0 2 2
91 2 ▶ if ( $WARNINGS_ARE eq $W_WARNING ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Gentoo::Overlay::Exceptions::WARNINGS_ARE eq $Gentoo::Overlay::Exceptions::W_WARNING) 1 1 2
92 ## no critic ( ErrorHandling::RequireCarping )
93 1 return warn __PACKAGE__->new(@_);
94 }
95 1 return __PACKAGE__->throw(@_);
96 }
97  
98  
99  
100  
101  
102 6 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=3 SCAR=16.0
Pod undocumented
103 6 my ( undef, @args ) = @_;
104 6 ▶ if ( 1 == scalar @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == scalar @args) 0 6 6
105 0 ▶ if ( not ref $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args[0]) 0 0 0
106 0 return { ident => $args[0] };
107 }
108 0 return $args[0];
109 }
110 6 return {@args};
111 }
112 has 'message_fmt' => (
113 is => 'ro',
114 isa => Str,
115 lazy => 1,
116 required => 1,
117 init_arg => 'message',
118 0 ▶ default => sub { shift->ident },
Subroutine __ANON__: not called CC=1 SCAR=6.9
119 7 );
120 7 with( 'Throwable', 'StackTrace::Auto', );
121  
122 6 ▶sub message {
Subroutine message: called CC=1 SCAR=0.2
Pod undocumented
123 6 my ($self) = @_;
124 6 ▶ return try {
Subroutine __ANON__: called CC=1 SCAR=0.0
125 6 errf( $self->message_fmt, $self->payload );
126 }
127 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
128 0 sprintf '%s (error during formatting)', $self->message_fmt;
129 6 },;
130 }
131  
132 7 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
133  
134 7 1;
135  
136 __END__
« Overlay/Types.pm ↑ Summary Overlay/Package.pm »