blib/lib/Hades/Realm/Moose.pm

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