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