Hades/Myths.pm

filter: Statementstmt 87.9% 51 / 58 Branchbran 54.1% 13 / 24 Conditioncond 38.4% 5 / 13 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 83.3% 10 / 12 Podpod 100% 2 / 2 totaltotal 70.0% 82 / 117 SCAR 33.4
CC
20
Cov
73%
new
18.6
import
15.2
new_object
2.0
CRAP 28.2
« Hades/Myths/Object.pm ↑ Summary Hades/Macro.pm »
1 package Hades::Myths;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use POSIX qw/locale_h/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 our $VERSION = 0.21;
6 14 our ($STASH);
7  
8 sub new {
9 4 ▶ my ( $cls, %args ) = ( shift(), scalar @_ == 1 ? %{ $_[0] } : @_ );
Subroutine new: called CC=7 SCAR=29.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 ? : 3 1 4
10 4 my $self = bless {}, $cls;
11 4 my %accessors = ();
12 4 for my $accessor ( keys %accessors ) {
13 my $param
14 = defined $args{$accessor}
15 ? $args{$accessor}
16 0 ▶ : $accessors{$accessor}->{default};
Branch: 1 branch
BranchTrueFalseTotal
defined $args{$accessor} ? : 0 0 0
17 my $value
18 = $self->$accessor( $accessors{$accessor}->{builder}
19 0 ▶ ? $accessors{$accessor}->{builder}->( $self, $param )
Branch: 1 branch
BranchTrueFalseTotal
$accessors{$accessor}{'builder'} ? : 0 0 0
20 : $param );
21 0 ▶ unless ( !$accessors{$accessor}->{required} || defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not $accessors{$accessor}{"required"} or defined $value) 0 0 0
Condition0%0/3
not $accessors{$accessor}{"required"} or defined $value
l!l&&r!l&&!r
000
MC/DC0%0/2
not $accessors{$accessor}{"required"} or defined $value
not $accessors{$accessor}{"required"} defined $value
Truth table0%0/3
not(A) or B
A= not $accessors{$accessor}{"required"}B= defined $value
ABresult
1X1
011
000
22 0 die "$accessor accessor is required";
23 }
24 }
25 4 return $self;
26 }
27  
28 sub import {
29 16 ▶ my ( $self, $locales, @additional ) = @_;
Subroutine import: called CC=14 SCAR=27.2
30 16 ▶ if ( defined $locales ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $locales) 15 1 16
31 15 ▶ if ( ( ref($locales) || "" ) ne "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $locales || "") ne "HASH") 2 13 15
Condition100%2/2
ref $locales || ''
l!l
141
MC/DC100%1/1
ref $locales || ''
ref $locales
Truth table100%2/2
A
A= ref $locales
Aresult
11
00
32 2 die
33 qq{Optional[HashRef]: invalid value $locales for variable \$locales in method import};
34 }
35 }
36 14 my $caller = caller();
37 14 ▶ $STASH = delete $locales->{stash} || 'Hades::Myths::Object';
Condition50%1/2
delete $locales->{'stash'} || 'Hades::Myths::Object'
l!l
014
MC/DC0%0/1
delete $locales->{'stash'} || 'Hades::Myths::Object'
delete $locales->{'stash'}
Truth table50%1/2
A
A= delete $locales->{'stash'}
Aresult
11
00
38 14 eval "require $STASH";
39 my ( $locale, $lang, $fb ) = $STASH->convert_locale(
40 delete $locales->{locale} || setlocale(LC_CTYPE),
41 , delete $locales->{fb},
42 14 ▶ );
Condition33%1/3
delete $locales->{'locale'} || setlocale(0)
l!l&&r!l&&!r
0140
MC/DC0%0/2
delete $locales->{'locale'} || setlocale(0)
delete $locales->{'locale'} setlocale(0)
Truth table33%1/3
A || B
A= delete $locales->{'locale'}B= setlocale(0)
ABresult
1X1
011
000
43 14 my $as_keyword = delete $locales->{as_keywords};
44 14 ▶ $locales = undef if ( !ref $locales || !scalar keys %{$locales} );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $locales and scalar keys %{$locales;} 14 0 14
Condition33%1/3
ref $locales and scalar keys %{$locales;}
!ll&&!rl&&r
0140
MC/DC0%0/2
ref $locales and scalar keys %{$locales;}
ref $locales scalar keys %{$locales;}
Truth table33%1/3
A and B
A= ref $localesB= scalar keys %{$locales;}
ABresult
0X0
100
111
45 14 ▶ my ($new) = $STASH->new(
Branch: 4 branches
BranchTrueFalseTotal
defined $fb ? : 14 0 14
defined $lang ? : 14 0 14
defined $locale ? : 14 0 14
defined $locales ? : 0 14 14
46 ( defined $fb ? ( fb => $fb ) : () ),
47 ( defined $lang ? ( language => $lang ) : () ),
48 ( defined $locale ? ( locale => $locale ) : () ),
49 ( defined $locales ? ( locales => $locales ) : () ),
50 @additional
51 );
52 {
53 14 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
54 14 ▶ no warnings "redefine";
Subroutine BEGIN: called CC=1 SCAR=0.0
55 14 ▶ *{"${caller}::locales"} = sub {$new};
Subroutine __ANON__: not called CC=1 SCAR=0.4
56 14 ▶ if ($as_keyword) {
Branch: 1 branch
BranchTrueFalseTotal
if ($as_keyword) 13 1 14
57 13 for my $key ( keys %{ $new->locales } ) {
58 14 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
59 14 ▶ no warnings "redefine";
Subroutine BEGIN: called CC=1 SCAR=0.0
60 650 ▶ *{"${caller}::${key}"} = sub { $new->string( $key, @_ ); };
Subroutine __ANON__: called CC=1 SCAR=0.0
61 }
62 }
63 };
64 }
65  
66 sub new_object {
67 0 ▶ my ( $self, %object ) = @_;
Subroutine new_object: not called CC=1 SCAR=6.9
Pod documented
68  
69 0 return $STASH->new(%object);
70  
71 }
72  
73 14 1;
74  
75 __END__
76  
77 =head1 NAME
78  
79 Hades::Myths - error handling for hades.
80  
81 =head1 VERSION
82  
83 Version 0.01
84  
85 =cut
86  
87 =head1 SYNOPSIS
88  
89 use Hades::Myths;
90  
91 say stranger;
92 die locales->stranger;
93  
94 =head1 SUBROUTINES/METHODS
95  
96 =head2 new
97  
98 Instantiate a new Hades::Myths object.
99  
100 Hades::Myths->new
101  
102 =head2 import
103  
104 call import method. Expects param $locales to be a Optional[HashRef], param @additional to be any value including undef.
105  
106 $obj->import($locales, @additional)
107  
108 =head2 new_object
109  
110 Accepts a list of arguments that are used to build a new Hades::Myths::Object.
111
112  
113 Hades::Myths::Object->new_object(
114 locale => $locale,
115 locales => {
116 %locales
117 }
118 );
119
120  
121 =head1 AUTHOR
122  
123 LNATION, C<< <email at lnation.org> >>
124  
125 =head1 BUGS
126  
127 Please report any bugs or feature requests to C<bug-hades::myths at rt.cpan.org>, or through
128 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hades-Myths>. I will be notified, and then you'll
129 automatically be notified of progress on your bug as I make changes.
130  
131 =head1 SUPPORT
132  
133 You can find documentation for this module with the perldoc command.
134  
135 perldoc Hades::Myths
136  
137 You can also look for information at:
138  
139 =over 4
140  
141 =item * RT: CPAN's request tracker (report bugs here)
142  
143 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Hades-Myths>
144  
145 =item * AnnoCPAN: Annotated CPAN documentation
146  
147 L<http://annocpan.org/dist/Hades-Myths>
148  
149 =item * CPAN Ratings
150  
151 L<https://cpanratings.perl.org/d/Hades-Myths>
152  
153 =item * Search CPAN
154  
155 L<https://metacpan.org/release/Hades-Myths>
156  
157 =back
158  
159 =head1 ACKNOWLEDGEMENTS
160  
161 =head1 LICENSE AND COPYRIGHT
162  
163 This software is Copyright (c) 2020 by LNATION.
164  
165 This is free software, licensed under:
166  
167 The Artistic License 2.0 (GPL Compatible)
168  
169 =cut
170  
171
« Hades/Myths/Object.pm ↑ Summary Hades/Macro.pm »