blib/lib/Hades/Realm/Moose.pm

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