blib/lib/Hades/Realm/Mouse.pm

filter: Statementstmt 94.0% 63 / 67 Branchbran 63.6% 28 / 44 Conditioncond 60.0% 15 / 25 MC/DCmcdc 43.7% 7 / 16 Subroutinesub 100% 10 / 10 Podpod 100% 7 / 7 totaltotal 76.9% 130 / 169 CC 33 SCAR 21.2
CC
33
Cov
78%
new
18.6
build_accessor_builder
8.6
build_accessor_predicate
7.3
CRAP 8.3
↑ Summary
1 package Hades::Realm::Mouse;
2 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use base qw/Hades::Realm::OO/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 our $VERSION = 0.03;
6  
7 sub new {
8 14 ▶ my ( $cls, %args ) = ( shift(), scalar @_ == 1 ? %{ $_[0] } : @_ );
Subroutine new: called CC=7 SCAR=29.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 ? : 13 1 14
9 14 my $self = $cls->SUPER::new(%args);
10 14 my %accessors = ();
11 14 for my $accessor ( keys %accessors ) {
12 my $param
13 = defined $args{$accessor}
14 ? $args{$accessor}
15 0 ▶ : $accessors{$accessor}->{default};
Branch: 1 branch
BranchTrueFalseTotal
defined $args{$accessor} ? : 0 0 0
16 my $value
17 = $self->$accessor( $accessors{$accessor}->{builder}
18 0 ▶ ? $accessors{$accessor}->{builder}->( $self, $param )
Branch: 1 branch
BranchTrueFalseTotal
$accessors{$accessor}{'builder'} ? : 0 0 0
19 : $param );
20 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
21 0 die "$accessor accessor is required";
22 }
23 }
24 14 return $self;
25 }
26  
27 sub build_as_role {
28 1 ▶ my ( $orig, $self, @params ) = ( 'SUPER::build_as_role', @_ );
Subroutine build_as_role: called CC=2 SCAR=7.0
Pod documented
29 1 my @res = $self->$orig(@params);
30 1 $res[0]->use(q|Mouse::Role|);
31 $res[0]->use(
32 sprintf q|Types::Standard qw/%s/|,
33 1 join( ' ', keys %{ $self->meta->{ $self->current_class }->{types} } )
34 );
35  
36 1 ▶ return wantarray ? @res : $res[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
37 }
38  
39 sub build_as_class {
40 9 ▶ my ( $orig, $self, @params ) = ( 'SUPER::build_as_class', @_ );
Subroutine build_as_class: called CC=2 SCAR=7.0
Pod documented
41 9 my @res = $self->$orig(@params);
42 9 $res[0]->use(q|Mouse|);
43 $res[0]->use(
44 sprintf q|Types::Standard qw/%s/|,
45 9 join( ' ', keys %{ $self->meta->{ $self->current_class }->{types} } )
46 );
47  
48 9 ▶ return wantarray ? @res : $res[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 9 9
49 }
50  
51 sub build_has {
52 38 ▶ my ( $self, $meta ) = @_;
Subroutine build_has: called CC=6 SCAR=18.0
Pod documented
53 38 ▶ if ( ( ref($meta) || "" ) ne "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $meta || "") ne "HASH") 2 36 38
Condition100%2/2
ref $meta || ''
l!l
371
MC/DC100%1/1
ref $meta || ''
ref $meta
Truth table100%2/2
A
A= ref $meta
Aresult
11
00
54 2 ▶ $meta = defined $meta ? $meta : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $meta ? : 2 0 2
55 2 die
56 qq{HashRef: invalid value $meta for variable \$meta in method build_has};
57 }
58  
59 36 ▶ $meta->{is} ||= '"rw"';
Condition50%1/2
$meta->{"is"} ||= "\"rw\""
l!l
036
MC/DC0%0/1
$meta->{"is"} ||= "\"rw\""
$meta->{"is"}
Truth table50%1/2
A
A= $meta->{"is"}
Aresult
11
00
60 my $attributes = join ', ',
61 36 ▶ map { ( $meta->{$_} ? ( sprintf "%s => %s", $_, $meta->{$_} ) : () ) }
Branch: 1 branch
BranchTrueFalseTotal
$meta->{$_} ? : 113 175 288
62 qw/is required clearer predicate isa default trigger builder/;
63 36 my $name = $meta->{has};
64 36 my $code = qq{has $name => ( $attributes );};
65 36 return $code;
66  
67 }
68  
69 sub build_accessor_predicate {
70 10 ▶ my ( $self, $name, $content ) = @_;
Subroutine build_accessor_predicate: called CC=7 SCAR=19.9
Pod documented
71 10 ▶ if ( !defined($name) || ref $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or ref $name) 2 8 10
Condition66%2/3
not defined $name or ref $name
l!l&&r!l&&!r
028
MC/DC50%1/2
not defined $name or ref $name
not defined $name ref $name
Truth table66%2/3
not(A) or B
A= not defined $nameB= ref $name
ABresult
1X1
011
000
72 2 ▶ $name = defined $name ? $name : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 2 0 2
73 2 die
74 qq{Str: invalid value $name for variable \$name in method build_accessor_predicate};
75 }
76 8 ▶ if ( !defined($content) || ref $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $content or ref $content) 2 6 8
Condition66%2/3
not defined $content or ref $content
l!l&&r!l&&!r
026
MC/DC50%1/2
not defined $content or ref $content
not defined $content ref $content
Truth table66%2/3
not(A) or B
A= not defined $contentB= ref $content
ABresult
1X1
011
000
77 2 ▶ $content = defined $content ? $content : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $content ? : 2 0 2
78 2 die
79 qq{Str: invalid value $content for variable \$content in method build_accessor_predicate};
80 }
81  
82 6 return qq|"has_$name"|;
83  
84 }
85  
86 sub build_accessor_clearer {
87 14 ▶ my ( $self, $name, $content ) = @_;
Subroutine build_accessor_clearer: called CC=7 SCAR=19.9
Pod documented
88 14 ▶ if ( !defined($name) || ref $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or ref $name) 2 12 14
Condition66%2/3
not defined $name or ref $name
l!l&&r!l&&!r
0212
MC/DC50%1/2
not defined $name or ref $name
not defined $name ref $name
Truth table66%2/3
not(A) or B
A= not defined $nameB= ref $name
ABresult
1X1
011
000
89 2 ▶ $name = defined $name ? $name : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 2 0 2
90 2 die
91 qq{Str: invalid value $name for variable \$name in method build_accessor_clearer};
92 }
93 12 ▶ if ( !defined($content) || ref $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $content or ref $content) 2 10 12
Condition66%2/3
not defined $content or ref $content
l!l&&r!l&&!r
0210
MC/DC50%1/2
not defined $content or ref $content
not defined $content ref $content
Truth table66%2/3
not(A) or B
A= not defined $contentB= ref $content
ABresult
1X1
011
000
94 2 ▶ $content = defined $content ? $content : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $content ? : 2 0 2
95 2 die
96 qq{Str: invalid value $content for variable \$content in method build_accessor_clearer};
97 }
98  
99 10 return qq|"clear_$name"|;
100  
101 }
102  
103 sub build_accessor_builder {
104 5 ▶ my ( $self, $name, $content ) = @_;
Subroutine build_accessor_builder: called CC=8 SCAR=21.5
Pod documented
105 5 ▶ if ( !defined($name) || ref $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or ref $name) 2 3 5
Condition66%2/3
not defined $name or ref $name
l!l&&r!l&&!r
023
MC/DC50%1/2
not defined $name or ref $name
not defined $name ref $name
Truth table66%2/3
not(A) or B
A= not defined $nameB= ref $name
ABresult
1X1
011
000
106 2 ▶ $name = defined $name ? $name : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $name ? : 2 0 2
107 2 die
108 qq{Str: invalid value $name for variable \$name in method build_accessor_builder};
109 }
110 3 ▶ if ( !defined($content) || ref $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $content or ref $content) 2 1 3
Condition66%2/3
not defined $content or ref $content
l!l&&r!l&&!r
021
MC/DC50%1/2
not defined $content or ref $content
not defined $content ref $content
Truth table66%2/3
not(A) or B
A= not defined $contentB= ref $content
ABresult
1X1
011
000
111 2 ▶ $content = defined $content ? $content : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $content ? : 2 0 2
112 2 die
113 qq{Str: invalid value $content for variable \$content in method build_accessor_builder};
114 }
115  
116 1 ▶ return $content =~ m/^\w\w+$/ ? $content : qq|"_build_$name"|;
Branch: 1 branch
BranchTrueFalseTotal
$content =~ /^\w\w+$/ ? : 0 1 1
117  
118 }
119  
120 8 1;
121  
122 __END__
123  
124 =head1 NAME
125  
126 Hades::Realm::Mouse - Hades realm for Mouse
127  
128 =head1 VERSION
129  
130 Version 0.01
131  
132 =cut
133  
134 =head1 SYNOPSIS
135  
136 Quick summary of what the module does:
137  
138 Hades->run({
139 eval => 'Kosmos { [curae penthos] :t(Int) :d(2) :pr :c :r geras $nosoi :t(Int) :d(5) { if (£penthos == $nosoi) { return £curae; } } }',
140 realm => 'Mouse',
141 });
142  
143 ... generates ...
144  
145 package Kosmos;
146 use strict;
147 use warnings;
148 use Mouse;
149 use Types::Standard qw/Int/;
150 our $VERSION = 0.01;
151  
152 has curae => (
153 is => "rw",
154 required => 1,
155 clearer => "clear_curae",
156 predicate => "has_curae",
157 isa => Int,
158 default => sub {2}
159 );
160  
161 has penthos => (
162 is => "rw",
163 required => 1,
164 clearer => "clear_curae",
165 predicate => "has_curae",
166 isa => Int,
167 default => sub {2}
168 );
169  
170 sub geras {
171 my ( $self, $nosoi ) = @_;
172 $nosoi = defined $nosoi ? $nosoi : 5;
173 if ( !defined($nosoi) || ref $nosoi || $nosoi !~ m/^[-+\d]\d*$/ ) {
174 $nosoi = defined $nosoi ? $nosoi : 'undef';
175 die qq{Int: invalid value $nosoi for variable \$nosoi in method geras};
176 }
177 if ( £penthos == $nosoi ) { return £curae; }
178 }
179  
180 1;
181  
182 __END__
183
184 NOTE: coerce and private attributes currently do not work with Mouse.
185  
186 =head1 SUBROUTINES/METHODS
187  
188 =head2 new
189  
190 Instantiate a new Hades::Realm::Mouse object.
191  
192 Hades::Realm::Mouse->new
193  
194 =head2 build_as_role
195  
196 call build_as_role method.
197  
198 =head2 build_as_class
199  
200 call build_as_class method.
201  
202 =head2 build_has
203  
204 call build_has method. Expects param $meta to be a HashRef.
205  
206 $obj->build_has($meta)
207  
208 =head2 build_accessor_predicate
209  
210 call build_accessor_predicate method. Expects param $name to be a Str, param $content to be a Str.
211  
212 $obj->build_accessor_predicate($name, $content)
213  
214 =head2 build_accessor_clearer
215  
216 call build_accessor_clearer method. Expects param $name to be a Str, param $content to be a Str.
217  
218 $obj->build_accessor_clearer($name, $content)
219  
220 =head2 build_accessor_builder
221  
222 call build_accessor_builder method. Expects param $name to be a Str, param $content to be a Str.
223  
224 $obj->build_accessor_builder($name, $content)
225  
226 =head1 AUTHOR
227  
228 LNATION, C<< <email at lnation.org> >>
229  
230 =head1 BUGS
231  
232 Please report any bugs or feature requests to C<bug-hades::realm::mouse at rt.cpan.org>, or through
233 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hades-Realm-Mouse>. I will be notified, and then you'll
234 automatically be notified of progress on your bug as I make changes.
235  
236 =head1 SUPPORT
237  
238 You can find documentation for this module with the perldoc command.
239  
240 perldoc Hades::Realm::Mouse
241  
242 You can also look for information at:
243  
244 =over 4
245  
246 =item * RT: CPAN's request tracker (report bugs here)
247  
248 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Hades-Realm-Mouse>
249  
250 =item * AnnoCPAN: Annotated CPAN documentation
251  
252 L<http://annocpan.org/dist/Hades-Realm-Mouse>
253  
254 =item * CPAN Ratings
255  
256 L<https://cpanratings.perl.org/d/Hades-Realm-Mouse>
257  
258 =item * Search CPAN
259  
260 L<https://metacpan.org/release/Hades-Realm-Mouse>
261  
262 =back
263  
264 =head1 ACKNOWLEDGEMENTS
265  
266 =head1 LICENSE AND COPYRIGHT
267  
268 This software is Copyright (c) 2020 by LNATION.
269  
270 This is free software, licensed under:
271  
272 The Artistic License 2.0 (GPL Compatible)
273  
274 =cut
275  
276
↑ Summary