| 1 | package Game::Life::NDim::Dim; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Created on: 2010-01-08 18:43:32 | ||||||||||||||||||||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Data::Dumper qw/Dumper/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | use overload | ||||||||||||||||||||||||||||
| 17 | 2034 | ▶ | '""' => sub { '[' . ( join ',', @{ $_[0]->elements } ) . ']' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 13450 | ▶ | '@{}' => sub { $_[0]->elements }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | '==' => sub { for (0..@{$_->[0]}-1) { return 0 if $_[0][$_] != $_[1][$_] } return 1 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 4 | ▶ | '+' => \&sum_list; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 4 | our $VERSION = version->new('0.0.3'); | |||||||||||||||||||||||||||
| 23 | 4 | our @EXPORT_OK = qw//; | |||||||||||||||||||||||||||
| 24 | 4 | our %EXPORT_TAGS = (); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 4 | has elements => ( | |||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||
| 28 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 29 | required => 1, | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | has max => ( | |||||||||||||||||||||||||||
| 33 | is => 'rw', | ||||||||||||||||||||||||||||
| 34 | isa => 'ArrayRef[Int]', | ||||||||||||||||||||||||||||
| 35 | weak_ref => 1, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | around new => sub { | ||||||||||||||||||||||||||||
| 39 | 1696 | ▶ | my ($new, $class, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1696 | ▶ | if ( @args == 1 && ref $args[0] eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args == 1 and ref $args[0] eq "ARRAY"
MC/DC50%1/2
@args == 1 and ref $args[0] eq "ARRAY"
@args == 1
ref $args[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 42 | 1692 | @args = ( elements => $args[0] ); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||
| 45 | 4 | my %params = @args; | |||||||||||||||||||||||||||
| 46 | 4 | ▶ | if (!exists $params{elements} && exists $params{max}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not exists $params{"elements"} and exists $params{"max"}
MC/DC50%1/2
not exists $params{"elements"} and exists $params{"max"}
not exists $params{"elements"}
exists $params{"max"}
Truth table66%2/3
not(A) and B
A= not exists $params{"elements"}B= exists $params{"max"}
| |||||||||||||||||||||||||||||
| 47 | 1 | $params{elements} = [ @{ $params{max} } ]; | |||||||||||||||||||||||||||
| 48 | 1 | return $new->($class, %params)->zero; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1695 | return $new->($class, @args); | |||||||||||||||||||||||||||
| 53 | 4 | }; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub increment { | ||||||||||||||||||||||||||||
| 56 | 1033 | ▶ | my ($self, $max) = @_; | ||||||||||||||||||||||||||
|
Subroutine
increment: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 1033 | my $last; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1033 | for my $i ( reverse 0 .. @{ $max } - 1 ) { | |||||||||||||||||||||||||||
| 60 | 1156 | ▶ | die "max[$i] == 0 which is not allowed!" if $max->[$i] == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 1156 | ▶ | if ( $self->[$i] + 1 <= $max->[$i] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 1028 | $self->[$i]++; | |||||||||||||||||||||||||||
| 63 | 1028 | $last = $i; | |||||||||||||||||||||||||||
| 64 | 1028 | last; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 128 | $self->[$i] = 0; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1033 | ▶ | return if !defined $last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1028 | return $self; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub clone { | ||||||||||||||||||||||||||||
| 75 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 3 | return $self->new(elements => [ @{ $self } ]); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub zero { | ||||||||||||||||||||||||||||
| 81 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
zero: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 2 | for my $item (@{ $self }) { | |||||||||||||||||||||||||||
| 84 | 6 | $item = 0; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 2 | return $self; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub sum_list { | ||||||||||||||||||||||||||||
| 91 | 36 | ▶ | my ($self, $list) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sum_list: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 36 | my @new; | |||||||||||||||||||||||||||
| 94 | 36 | for my $i ( 0 .. @{ $self } - 1 ) { | |||||||||||||||||||||||||||
| 95 | 96 | ▶ | die Dumper $i, $self, $list if !defined $self->[$i] || !defined $list->[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->[$i] and defined $list->[$i]
MC/DC0%0/2
defined $self->[$i] and defined $list->[$i]
defined $self->[$i]
defined $list->[$i]
Truth table33%1/3
A and B
A= defined $self->[$i]B= defined $list->[$i]
| |||||||||||||||||||||||||||||
| 96 | 96 | $new[$i] = $self->[$i] + $list->[$i]; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 36 | return __PACKAGE__->new(\@new); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 4 | 1; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 NAME | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | Game::Life::NDim::Dim - The dimension of a board? | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 VERSION | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | This documentation refers to Game::Life::NDim::Dim version 0.0.3. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | use Game::Life::NDim::Dim; | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # Brief but working code example(s) here showing the most common usage(s) | ||||||||||||||||||||||||||||
| 120 | # This section will be as far as many users bother reading, so make it as | ||||||||||||||||||||||||||||
| 121 | # educational and exemplary as possible. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head2 C<increment ( )> | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head2 C<clone ( )> | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head2 C<zero ( )> | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head2 C<sum_list ( )> | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head1 DIAGNOSTICS | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head1 INCOMPATIBILITIES | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | There are no known bugs in this module. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Please report problems to Ivan Wills (ivan.wills@gmail.com). | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | Patches are welcome. | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | Ivan Wills - (ivan.wills@gmail.com) | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | Copyright (c) 2010 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). | ||||||||||||||||||||||||||||
| 159 | All rights reserved. | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | This module is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 162 | the same terms as Perl itself. See L<perlartistic>. This program is | ||||||||||||||||||||||||||||
| 163 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||||||||||||||||||||||||||||
| 164 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||||||||||||||||
| 165 | PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||||||||||