Hades/Macro.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 89.2% 25 / 28 Conditioncond 85.7% 12 / 14 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 100% 7 / 7 Podpod 100% 5 / 5 totaltotal 93.0% 107 / 115 SCAR 32.6
CC
26
Cov
94%
meta
9.0
alias
9.0
new
7.7
CRAP 26.2
« Hades/Myths.pm ↑ Summary
1 package Hades::Macro;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 our $VERSION = 0.21;
5  
6 sub new {
7 63 ▶ my ( $cls, %args ) = ( shift(), scalar @_ == 1 ? %{ $_[0] } : @_ );
Subroutine new: called CC=7 SCAR=20.4
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 ? : 14 49 63
8 63 my $self = bless {}, $cls;
9 63 my %accessors = ( alias => {}, macro => { default => [], }, );
10 63 for my $accessor ( keys %accessors ) {
11 my $param
12 = defined $args{$accessor}
13 ? $args{$accessor}
14 121 ▶ : $accessors{$accessor}->{default};
Branch: 1 branch
BranchTrueFalseTotal
defined $args{$accessor} ? : 21 100 121
15 my $value
16 = $self->$accessor( $accessors{$accessor}->{builder}
17 121 ▶ ? $accessors{$accessor}->{builder}->( $self, $param )
Branch: 1 branch
BranchTrueFalseTotal
$accessors{$accessor}{'builder'} ? : 0 121 121
18 : $param );
19 110 ▶ unless ( !$accessors{$accessor}->{required} || defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not $accessors{$accessor}{"required"} or defined $value) 0 110 110
Condition33%1/3
not $accessors{$accessor}{"required"} or defined $value
l!l&&r!l&&!r
11000
MC/DC0%0/2
not $accessors{$accessor}{"required"} or defined $value
not $accessors{$accessor}{"required"} defined $value
Truth table33%1/3
not(A) or B
A= not $accessors{$accessor}{"required"}B= defined $value
ABresult
1X1
011
000
20 0 die "$accessor accessor is required";
21 }
22 }
23 52 return $self;
24 }
25  
26 sub macro {
27 18 ▶ my ( $self, $value ) = @_;
Subroutine macro: called CC=4 SCAR=13.9
Pod documented
28 18 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 16 2 18
29 16 ▶ if ( ( ref($value) || "" ) ne "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $value || "") ne "ARRAY") 4 12 16
Condition100%2/2
ref $value || ''
l!l
142
MC/DC100%1/1
ref $value || ''
ref $value
Truth table100%2/2
A
A= ref $value
Aresult
11
00
30 4 die qq{ArrayRef: invalid value $value for accessor macro};
31 }
32 12 $self->{macro} = $value;
33 }
34 14 return $self->{macro};
35 }
36  
37 sub alias {
38 75 ▶ my ( $self, $value ) = @_;
Subroutine alias: called CC=9 SCAR=22.0
Pod documented
39 75 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 17 58 75
40 17 ▶ if ( ( ref($value) || "" ) ne "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $value || "") ne "HASH") 4 13 17
Condition100%2/2
ref $value || ''
l!l
152
MC/DC100%1/1
ref $value || ''
ref $value
Truth table100%2/2
A
A= ref $value
Aresult
11
00
41 4 die
42 qq{HashRef[ArrayRef]: invalid value $value for accessor alias};
43 }
44 13 for my $item ( values %{$value} ) {
45 14 ▶ if ( !defined($item) || ( ref($item) || "" ) ne "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $item or (ref $item || "") ne "ARRAY") 6 8 14
Condition100%5/5
not defined $item or (ref $item || "") ne "ARRAY"
l!l&&r!l&&!r
248
ref $item || ''
l!l
102
MC/DC100%2/2
not defined $item or (ref $item || "") ne "ARRAY"
not defined $item ref $item
Truth table100%3/3
not(A) or B
A= not defined $itemB= ref $item
ABresult
1X1
011
000
46 6 ▶ $item = defined $item ? $item : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $item ? : 4 2 6
47 6 die
48 qq{HashRef[ArrayRef]: invalid value $item for accessor alias expected ArrayRef};
49 }
50 }
51 7 $self->{alias} = $value;
52 }
53 65 return $self->{alias};
54 }
55  
56 sub has_alias {
57 4 ▶ my ($self) = @_;
Subroutine has_alias: called CC=1 SCAR=0.0
Pod documented
58 4 return exists $self->{alias};
59 }
60  
61 sub meta {
62 4 ▶ my ( $self, $meta ) = @_;
Subroutine meta: called CC=9 SCAR=22.0
Pod documented
63 4 ▶ $meta = defined $meta ? $meta : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $meta ? : 2 2 4
64 4 ▶ if ( ( ref($meta) || "" ) ne "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $meta || "") ne "HASH") 2 2 4
Condition100%2/2
ref $meta || ''
l!l
31
MC/DC100%1/1
ref $meta || ''
ref $meta
Truth table100%2/2
A
A= ref $meta
Aresult
11
00
65 2 ▶ $meta = defined $meta ? $meta : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $meta ? : 2 0 2
66 2 die
67 qq{HashRef: invalid value $meta for variable \$meta in method meta};
68 }
69  
70 2 my $cls = ref $self;
71 2 for my $m ( @{ $self->macro } ) {
72 $meta->{$m} = {
73 meta => 'MACRO',
74 29 code => \&{"${cls}::${m}"},
75 };
76 }
77 2 ▶ if ( $self->has_alias ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_alias) 1 1 2
78 1 for my $key ( %{ $self->alias } ) {
79 4 for my $alias ( @{ $self->alias()->{$key} } ) {
80 2 $meta->{$alias} = $meta->{$key};
81 }
82 }
83 }
84 2 return $meta;
85  
86 }
87  
88 5 1;
89  
90 __END__
91  
92 =head1 NAME
93  
94 Hades::Macro - Hades macro base class.
95  
96 =head1 VERSION
97  
98 Version 0.01
99  
100 =cut
101  
102 =head1 SYNOPSIS
103  
104 Quick summary of what the module does:
105  
106 Hades::Macro::Kosmos base Hades::Macro {
107 macro :t(ArrayRef) :d([qw/geras/])
108 geras $mg :t(Object) {
109 return q|...|;
110 }
111 }
112  
113 =head1 SUBROUTINES/METHODS
114  
115 =head2 new
116  
117 Instantiate a new Hades::Macro object.
118  
119 Hades::Macro->new
120  
121 =head2 has_alias
122  
123 has_alias will return true if alias accessor has a value.
124  
125 $obj->has_alias
126  
127 =head2 meta
128  
129 call meta method. Expects param $meta to be a HashRef.
130  
131 $obj->meta($meta)
132  
133 =head1 ACCESSORS
134  
135 =head2 macro
136  
137 get or set macro.
138  
139 $obj->macro;
140  
141 $obj->macro($value);
142  
143 =head2 alias
144  
145 get or set alias.
146  
147 $obj->alias;
148  
149 $obj->alias($value);
150  
151 =head1 AUTHOR
152  
153 LNATION, C<< <email at lnation.org> >>
154  
155 =head1 BUGS
156  
157 Please report any bugs or feature requests to C<bug-hades::macro at rt.cpan.org>, or through
158 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hades-Macro>. I will be notified, and then you'll
159 automatically be notified of progress on your bug as I make changes.
160  
161 =head1 SUPPORT
162  
163 You can find documentation for this module with the perldoc command.
164  
165 perldoc Hades::Macro
166  
167 You can also look for information at:
168  
169 =over 4
170  
171 =item * RT: CPAN's request tracker (report bugs here)
172  
173 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Hades-Macro>
174  
175 =item * AnnoCPAN: Annotated CPAN documentation
176  
177 L<http://annocpan.org/dist/Hades-Macro>
178  
179 =item * CPAN Ratings
180  
181 L<https://cpanratings.perl.org/d/Hades-Macro>
182  
183 =item * Search CPAN
184  
185 L<https://metacpan.org/release/Hades-Macro>
186  
187 =back
188  
189 =head1 ACKNOWLEDGEMENTS
190  
191 =head1 LICENSE AND COPYRIGHT
192  
193 This software is Copyright (c) 2020 by LNATION.
194  
195 This is free software, licensed under:
196  
197 The Artistic License 2.0 (GPL Compatible)
198  
199 =cut
200  
201
« Hades/Myths.pm ↑ Summary