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