blib/lib/Hades/Realm/Moo.pm

filter: Statementstmt 93.1% 41 / 44 Branchbran 56.2% 9 / 16 Conditioncond 42.8% 3 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 4 / 4 totaltotal 79.2% 65 / 82 CC 13 SCAR 18.5
CC
13
Cov
79%
new
12.2
build_has
6.0
build_as_role
2.0
CRAP 6.3
↑ Summary
1 package Hades::Realm::Moo;
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.02;
6  
7 sub new {
8 9 ▶ my ( $cls, %args ) = ( shift(), scalar @_ == 1 ? %{ $_[0] } : @_ );
Subroutine new: called CC=6 SCAR=25.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 ? : 8 1 9
9 9 my $self = $cls->SUPER::new(%args);
10 9 my %accessors = ();
11 9 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 9 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|Moo::Role|);
28 1 $res[0]->use(q|MooX::Private::Attribute|);
29 $res[0]->use(
30 sprintf q|Types::Standard qw/%s/|,
31 1 join( ' ', keys %{ $self->meta->{ $self->current_class }->{types} } )
32 );
33  
34 1 ▶ return wantarray ? @res : $res[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
35 }
36  
37 sub build_as_class {
38 6 ▶ my ( $orig, $self, @params ) = ( 'SUPER::build_as_class', @_ );
Subroutine build_as_class: called CC=2 SCAR=7.0
Pod documented
39 6 my @res = $self->$orig(@params);
40 6 $res[0]->use(q|Moo|);
41 6 $res[0]->use(q|MooX::Private::Attribute|);
42 $res[0]->use(
43 sprintf q|Types::Standard qw/%s/|,
44 6 join( ' ', keys %{ $self->meta->{ $self->current_class }->{types} } )
45 );
46  
47 6 ▶ return wantarray ? @res : $res[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 6 6
48 }
49  
50 sub build_has {
51 35 ▶ my ( $self, $meta ) = @_;
Subroutine build_has: called CC=6 SCAR=18.0
Pod documented
52 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
53 2 ▶ $meta = defined $meta ? $meta : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $meta ? : 2 0 2
54 2 die
55 qq{HashRef: invalid value $meta for variable \$meta in method build_has};
56 }
57  
58 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
59 my $attributes = join ', ',
60 33 ▶ map { ( $meta->{$_} ? ( sprintf "%s => %s", $_, $meta->{$_} ) : () ) }
Branch: 1 branch
BranchTrueFalseTotal
$meta->{$_} ? : 102 195 297
61 qw/is required clearer predicate isa private default coerce trigger/;
62 33 my $name = $meta->{has};
63 33 my $code = qq{
64 has $name => ( $attributes );};
65 33 return $code;
66  
67 }
68  
69 6 1;
70  
71 __END__
72  
73 =head1 NAME
74  
75 Hades::Realm::Moo - Hades realm for Moo
76  
77 =head1 VERSION
78  
79 Version 0.01
80  
81 =cut
82  
83 =head1 SYNOPSIS
84  
85 Quick summary of what the module does:
86  
87 Hades->run({
88 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; } } }',
89 realm => 'Moo',
90 });
91  
92 ... generates ...
93  
94 package Kosmos;
95 use strict;
96 use warnings;
97 use Moo;
98 use MooX::Private::Attribute;
99 use Types::Standard qw/Int/;
100 our $VERSION = 0.01;
101  
102 has curae => (
103 is => "rw",
104 required => 1,
105 clearer => 1,
106 predicate => 1,
107 isa => Int,
108 private => 1,
109 default => sub {2}
110 );
111  
112 has penthos => (
113 is => "rw",
114 required => 1,
115 clearer => 1,
116 predicate => 1,
117 isa => Int,
118 private => 1,
119 default => sub {2}
120 );
121  
122 sub geras {
123 my ( $self, $nosoi ) = @_;
124 $nosoi = defined $nosoi ? $nosoi : 5;
125 if ( !defined($nosoi) || ref $nosoi || $nosoi !~ m/^[-+\d]\d*$/ ) {
126 $nosoi = defined $nosoi ? $nosoi : 'undef';
127 die qq{Int: invalid value $nosoi for variable \$nosoi in method geras};
128 }
129 if ( $self->penthos == $nosoi ) { return $self->curae; }
130 }
131  
132 1;
133  
134 __END__
135  
136 =head1 SUBROUTINES/METHODS
137  
138 =head2 new
139  
140 Instantiate a new Hades::Realm::Moo object.
141  
142 Hades::Realm::Moo->new
143  
144 =head2 build_as_role
145  
146 call build_as_role method.
147  
148 =head2 build_as_class
149  
150 call build_as_class method.
151  
152 =head2 build_has
153  
154 call build_has method. Expects param $meta to be a HashRef.
155  
156 $obj->build_has($meta)
157  
158 =head1 AUTHOR
159  
160 LNATION, C<< <email at lnation.org> >>
161  
162 =head1 BUGS
163  
164 Please report any bugs or feature requests to C<bug-hades::realm::moo at rt.cpan.org>, or through
165 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hades-Realm-Moo>. I will be notified, and then you'll
166 automatically be notified of progress on your bug as I make changes.
167  
168 =head1 SUPPORT
169  
170 You can find documentation for this module with the perldoc command.
171  
172 perldoc Hades::Realm::Moo
173  
174 You can also look for information at:
175  
176 =over 4
177  
178 =item * RT: CPAN's request tracker (report bugs here)
179  
180 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Hades-Realm-Moo>
181  
182 =item * AnnoCPAN: Annotated CPAN documentation
183  
184 L<http://annocpan.org/dist/Hades-Realm-Moo>
185  
186 =item * CPAN Ratings
187  
188 L<https://cpanratings.perl.org/d/Hades-Realm-Moo>
189  
190 =item * Search CPAN
191  
192 L<https://metacpan.org/release/Hades-Realm-Moo>
193  
194 =back
195  
196 =head1 ACKNOWLEDGEMENTS
197  
198 =head1 LICENSE AND COPYRIGHT
199  
200 This software is Copyright (c) 2020 by LNATION.
201  
202 This is free software, licensed under:
203  
204 The Artistic License 2.0 (GPL Compatible)
205  
206 =cut
207  
208
↑ Summary