File Coverage

blib/lib/Hades/Realm/Rope.pm
Criterion Covered Total %
statement 68 79 86.0
branch 36 58 62.0
condition 18 31 58.0
subroutine 11 12 91.6
pod 9 9 100.0
total 142 189 75.1


line stmt bran cond sub pod time code
1             package Hades::Realm::Rope;
2 5     5   2507728 use strict;
  5         13  
  5         203  
3 5     5   68 use warnings;
  5         12  
  5         341  
4 5     5   31 use base qw/Hades::Realm::OO/;
  5         8  
  5         3402  
5             our $VERSION = 0.06;
6              
7             sub new {
8 13 100   13 1 272003 my ( $cls, %args ) = ( shift(), scalar @_ == 1 ? %{ $_[0] } : @_ );
  12         104  
9 13         122 my $self = $cls->SUPER::new(%args);
10 13         1190 my %accessors = ();
11 13         52 for my $accessor ( keys %accessors ) {
12             my $param
13             = defined $args{$accessor}
14             ? $args{$accessor}
15 0 0       0 : $accessors{$accessor}->{default};
16             my $value
17             = $self->$accessor( $accessors{$accessor}->{builder}
18 0 0       0 ? $accessors{$accessor}->{builder}->( $self, $param )
19             : $param );
20 0 0 0     0 unless ( !$accessors{$accessor}->{required} || defined $value ) {
21 0         0 die "$accessor accessor is required";
22             }
23             }
24 13         107 return $self;
25             }
26              
27             sub build_as_role {
28 0     0 1 0 my ( $orig, $self, @params ) = ( 'SUPER::build_as_role', @_ );
29 0         0 my @res = $self->$orig(@params);
30 0         0 $res[0]->use(q|Rope::Role|);
31             $res[0]->use(
32             sprintf q|Types::Standard qw/%s/|,
33 0         0 join( ' ', keys %{ $self->meta->{ $self->current_class }->{types} } )
  0         0  
34             );
35              
36 0 0       0 return wantarray ? @res : $res[0];
37             }
38              
39             sub build_as_class {
40 4     4 1 46682 my ( $orig, $self, @params ) = ( 'SUPER::build_as_class', @_ );
41 4         33 my @res = $self->$orig(@params);
42 4         79 $res[0]->use(q|Rope|);
43 4         65 $res[0]->use(q|Rope::Autoload|);
44             $res[0]->use(
45             sprintf q|Types::Standard qw/%s/|,
46 4         37 join( ' ', keys %{ $self->meta->{ $self->current_class }->{types} } )
  4         22  
47             );
48              
49 4 50       126 return wantarray ? @res : $res[0];
50             }
51              
52             sub build_has {
53 24     24 1 741519 my ( $self, $meta ) = @_;
54 24 100 100     97 if ( ( ref($meta) || "" ) ne "HASH" ) {
55 2 50       8 $meta = defined $meta ? $meta : 'undef';
56 2         28 die
57             qq{HashRef: invalid value $meta for variable \$meta in method build_has};
58             }
59              
60 22   50     122 $meta->{is} ||= '"rw"';
61             my $attributes = sprintf "initable => 1, writeable => %s,",
62 22 50       83 $meta->{is} =~ m/^ro$/ ? 0 : 1;
63 22 100       79 $attributes .= sprintf "type => %s,", $meta->{isa} if $meta->{isa};
64             $attributes .= join ', ',
65 22 100       41 map { ( $meta->{$_} ? ( sprintf "%s => %s", $_, $meta->{$_} ) : () ) }
  132         314  
66             qw/required clearer predicate trigger builder private/;
67             $attributes .= sprintf ", value => %s", $meta->{default}
68 22 100       81 if $meta->{default};
69 22         39 my $name = $meta->{has};
70 22         42 my $code = qq{
71             property $name => ( $attributes );
72             };
73 22         54 return $code;
74              
75             }
76              
77             sub build_accessor_predicate {
78 7     7 1 3665 my ( $self, $name, $content ) = @_;
79 7 100 66     69 if ( !defined($name) || ref $name ) {
80 2 50       8 $name = defined $name ? $name : 'undef';
81 2         27 die
82             qq{Str: invalid value $name for variable \$name in method build_accessor_predicate};
83             }
84 5 100 66     34 if ( !defined($content) || ref $content ) {
85 2 50       8 $content = defined $content ? $content : 'undef';
86 2         26 die
87             qq{Str: invalid value $content for variable \$content in method build_accessor_predicate};
88             }
89              
90 3         12 return qq|"has_$name"|;
91              
92             }
93              
94             sub build_accessor_clearer {
95 10     10 1 4756 my ( $self, $name, $content ) = @_;
96 10 100 66     75 if ( !defined($name) || ref $name ) {
97 2 50       7 $name = defined $name ? $name : 'undef';
98 2         47 die
99             qq{Str: invalid value $name for variable \$name in method build_accessor_clearer};
100             }
101 8 100 66     49 if ( !defined($content) || ref $content ) {
102 2 50       9 $content = defined $content ? $content : 'undef';
103 2         27 die
104             qq{Str: invalid value $content for variable \$content in method build_accessor_clearer};
105             }
106              
107 6         24 return qq|"clear_$name"|;
108              
109             }
110              
111             sub build_accessor_builder {
112 4     4 1 3137 my ( $self, $name, $content ) = @_;
113 4 100 66     32 if ( !defined($name) || ref $name ) {
114 2 50       7 $name = defined $name ? $name : 'undef';
115 2         29 die
116             qq{Str: invalid value $name for variable \$name in method build_accessor_builder};
117             }
118 2 50 33     17 if ( !defined($content) || ref $content ) {
119 2 50       9 $content = defined $content ? $content : 'undef';
120 2         28 die
121             qq{Str: invalid value $content for variable \$content in method build_accessor_builder};
122             }
123              
124 0 0       0 return $content =~ m/^\w\w+$/ ? $content : qq|"_build_$name"|;
125              
126             }
127              
128             sub build_accessor_default {
129 13     13 1 53092 my ( $self, $name, $content ) = @_;
130 13 100 66     91 if ( !defined($name) || ref $name ) {
131 2 50       8 $name = defined $name ? $name : 'undef';
132 2         30 die
133             qq{Str: invalid value $name for variable \$name in method build_accessor_default};
134             }
135 11 100 66     55 if ( !defined($content) || ref $content ) {
136 2 50       8 $content = defined $content ? $content : 'undef';
137 2         28 die
138             qq{Str: invalid value $content for variable \$content in method build_accessor_default};
139             }
140              
141 9         39 return $content;
142              
143             }
144              
145             sub has_function_keyword {
146 2     2 1 7162 my ($self) = @_;
147              
148 2         6 return 1;
149              
150             }
151              
152             1;
153              
154             __END__
155              
156             =head1 NAME
157              
158             Hades::Realm::Rope - Hades realm for Rope
159              
160             =head1 VERSION
161              
162             Version 0.06
163              
164             =cut
165              
166             =head1 SYNOPSIS
167              
168             Quick summary of what the module does:
169              
170             Hades->run({
171             eval => q|
172             Kosmos {
173             [curae penthos] :t(Int) :d(2) :p :pr :c :r
174             geras $nosoi :t(Int) :d(5) {
175             if (£penthos == $nosoi) {
176             return £curae;
177             }
178             }
179             }
180             |,
181             realm => 'Rope',
182             });
183              
184             ... generates ...
185              
186             package Kosmos;
187             use strict;
188             use warnings;
189             use Rope;
190             use Rope::Autoload;
191             use Types::Standard qw/Int/;
192             our $VERSION = 0.01;
193              
194             property curae => (
195             initable => 1,
196             writeable => 1,
197             type => Int,
198             required => 1,
199             clearer => "clear_curae",
200             predicate => "has_curae",
201             private => 1,
202             value => 2
203             );
204              
205             property penthos => (
206             initable => 1,
207             writeable => 1,
208             type => Int,
209             required => 1,
210             clearer => "clear_penthos",
211             predicate => "has_penthos",
212             private => 1,
213             value => 2
214             );
215              
216             function geras => sub {
217             my ( $self, $nosoi ) = @_;
218             $nosoi = defined $nosoi ? $nosoi : 5;
219             if ( !defined($nosoi) || ref $nosoi || $nosoi !~ m/^[-+\d]\d*$/ ) {
220             $nosoi = defined $nosoi ? $nosoi : 'undef';
221             die
222             qq{Int: invalid value $nosoi for variable \$nosoi in method geras};
223             }
224             if ( $self->penthos == $nosoi ) { return $self->curae; }
225             };
226              
227             1;
228              
229             __END__
230              
231             =head1 SUBROUTINES/METHODS
232              
233             =head2 new
234              
235             Instantiate a new Hades::Realm::Rope object.
236              
237             Hades::Realm::Rope->new
238              
239             =head2 build_as_role
240              
241             call build_as_role method.
242              
243             =head2 build_as_class
244              
245             call build_as_class method.
246              
247             =head2 build_has
248              
249             call build_has method. Expects param $meta to be a HashRef.
250              
251             $obj->build_has($meta)
252              
253             =head2 build_accessor_predicate
254              
255             call build_accessor_predicate method. Expects param $name to be a Str, param $content to be a Str.
256              
257             $obj->build_accessor_predicate($name, $content)
258              
259             =head2 build_accessor_clearer
260              
261             call build_accessor_clearer method. Expects param $name to be a Str, param $content to be a Str.
262              
263             $obj->build_accessor_clearer($name, $content)
264              
265             =head2 build_accessor_builder
266              
267             call build_accessor_builder method. Expects param $name to be a Str, param $content to be a Str.
268              
269             $obj->build_accessor_builder($name, $content)
270              
271             =head2 build_accessor_default
272              
273             call build_accessor_default method. Expects param $name to be a Str, param $content to be a Str.
274              
275             $obj->build_accessor_default($name, $content)
276              
277             =head2 has_function_keyword
278              
279             call has_function_keyword method. Expects no params.
280              
281             $obj->has_function_keyword()
282              
283             =head1 AUTHOR
284              
285             LNATION, C<< <email at lnation.org> >>
286              
287             =head1 BUGS
288              
289             Please report any bugs or feature requests to C<bug-hades::realm::rope at rt.cpan.org>, or through
290             the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hades-Realm-Rope>. I will be notified, and then you'll
291             automatically be notified of progress on your bug as I make changes.
292              
293             =head1 SUPPORT
294              
295             You can find documentation for this module with the perldoc command.
296              
297             perldoc Hades::Realm::Rope
298              
299             You can also look for information at:
300              
301             =over 4
302              
303             =item * RT: CPAN's request tracker (report bugs here)
304              
305             L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Hades-Realm-Rope>
306              
307             =item * AnnoCPAN: Annotated CPAN documentation
308              
309             L<http://annocpan.org/dist/Hades-Realm-Rope>
310              
311             =item * CPAN Ratings
312              
313             L<https://cpanratings.perl.org/d/Hades-Realm-Rope>
314              
315             =item * Search CPAN
316              
317             L<https://metacpan.org/release/Hades-Realm-Rope>
318              
319             =back
320              
321             =head1 ACKNOWLEDGEMENTS
322              
323             =head1 LICENSE AND COPYRIGHT
324              
325             This software is Copyright (c) 2020 by LNATION.
326              
327             This is free software, licensed under:
328              
329             The Artistic License 2.0 (GPL Compatible)
330              
331             =cut
332              
333