lib/Weaving/Tablet/Card.pm

filter: Statementstmt 97.9% 97 / 99 Branchbran 88.4% 23 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.4% 17 / 18 Podpod 0.0% 0 / 7 totaltotal 91.3% 137 / 150 CC 19 SCAR 12.2
CC
19
Cov
96%
__ANON__
6.0
twist_card
5.0
color_card
5.0
CRAP 3.4
« lib/Weaving/Tablet/Twill/Card.pm ↑ Summary lib/Weaving/snartemo.pl »
1 package Weaving::Tablet::Card;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 4 has 'number_of_holes' => (isa => 'Int', is => 'ro', default => 4);
9 4 has 'number_of_turns' => (isa => 'Int', is => 'ro', writer => '_set_turns');
10 4 has 'SZ' => (isa => 'Str', is => 'rw', default => 'S');
11 0 ▶has 'turns' => (isa => 'ArrayRef[Str]', is => 'ro', default => sub { [] });
Subroutine __ANON__: not called CC=1 SCAR=1.2
12 47 ▶has 'threading' => (isa => 'ArrayRef[Int]', is => 'ro', default => sub { [0,1,2,3] });
Subroutine __ANON__: called CC=1 SCAR=0.0
13 4 has 'start' => (isa => 'Int', is => 'rw', default => '0');
14 47 ▶has 'color' => (isa => 'ArrayRef[Int]', is => 'ro', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
15 47 ▶has 'twist' => (isa => 'ArrayRef[Int]', is => 'ro', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
16 47 ▶has 'floats' => (isa => 'ArrayRef', is => 'ro', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
17
18 4 our $VERSION = '0.9.2';
19
20 48 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
21 48 my $orig = shift;
22 48 my $class = shift;
23 48 ▶ my $args = @_ == 1 ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 1 47 48
24
25 48 ▶ if (exists $args->{turns})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args->{'turns'}) { } 3 45 48
elsif (exists $args->{'number_of_turns'}) { } 44 1 45
26 {
27 3 ▶ if (!ref $args->{turns})
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args->{"turns"}) 2 1 3
28 {
29 2 $args->{turns} = [split(//, $args->{turns})];
30 }
31 3 $args->{number_of_turns} = @{$args->{turns}};
32 }
33 elsif (exists $args->{number_of_turns})
34 {
35 44 $args->{turns} = [('/') x $args->{number_of_turns}];
36 }
37 else
38 {
39 1 die 'Must specify number_of_turns or turns';
40 }
41 47 ▶ if (exists $args->{start})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"start"}) 1 46 47
42 {
43 1 $args->{start} =~ tr/ABCDEFGH/01234567/;
44 }
45 47 return $class->$orig($args);
46 4 };
47
48 sub BUILD
49 47 ▶{
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
50 47 my $self = shift;
51 47 $self->color_card;
52 47 $self->twist_card;
53 }
54
55 sub set_threading
56 1 ▶{
Subroutine set_threading: called CC=2 SCAR=6.9
Pod undocumented
57 1 my $self = shift;
58 1 my ($threading) = @_;
59 1 for my $hole (0 .. $self->number_of_holes-1)
60 {
61 4 $self->threading->[$hole] = $threading->[$hole];
62 }
63 }
64
65 sub insert_picks
66 42 ▶{
Subroutine insert_picks: called CC=1 SCAR=0.0
Pod undocumented
67 42 my $self = shift;
68 42 my ($after, $picks) = @_;
69 42 my @picks = split(//, $picks);
70 42 splice @{$self->turns}, $after+1, 0, @picks;
71 42 $self->_set_turns(scalar @{$self->turns});
72 }
73
74 sub delete_picks
75 1 ▶{
Subroutine delete_picks: called CC=2 SCAR=6.9
Pod undocumented
76 1 my $self = shift;
77 1 my @picks = reverse sort { $a <=> $b } @_;
78 1 splice @{$self->turns}, $_, 1 for @picks;
79 1 $self->_set_turns(scalar @{$self->turns});
80 }
81
82 sub color_card
83 49 ▶{
Subroutine color_card: called CC=5 SCAR=16.1
Pod undocumented
84 49 my $self = shift;
85 49 my $color = $self->start;
86 49 my $pos = $color;
87 49 my $holes = $self->number_of_holes;
88 49 for my $pick (0 .. $self->number_of_turns-1)
89 {
90 482 my $turn = $self->turns->[$pick];
91 482 ▶ if ($turn ne '|')
Branch: 1 branch
BranchTrueFalseTotal
if ($turn ne "|") 482 0 482
92 {
93 482 ▶ $color = ($turn eq '/' ? $pos : $pos+1) % $holes;
Branch: 1 branch
BranchTrueFalseTotal
$turn eq '/' ? : 468 14 482
94 482 ▶ $pos = ($turn eq '/' ? $pos-1 : $pos+1) % $holes;
Branch: 1 branch
BranchTrueFalseTotal
$turn eq '/' ? : 468 14 482
95 }
96 482 $self->color->[$pick] = $color;
97 }
98 }
99
100 sub twist_card
101 67 ▶{
Subroutine twist_card: called CC=5 SCAR=16.1
Pod undocumented
102 67 my $self = shift;
103 67 my $twist = 0;
104 67 ▶ my $sign = $self->SZ eq 'S' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$self->SZ eq 'S' ? : 67 0 67
105 67 for my $pick (0 .. $self->number_of_turns-1)
106 {
107 662 ▶ $twist++ if $self->turns->[$pick] eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if $self->turns->[$pick] eq "/" 651 11 662
108 662 ▶ $twist-- if $self->turns->[$pick] eq '\\';
Branch: 1 branch
BranchTrueFalseTotal
if $self->turns->[$pick] eq "\\" 11 651 662
109 662 $self->twist->[$pick] = $twist * $sign;
110 }
111 }
112
113 sub float_card
114 2 ▶{
Subroutine float_card: called CC=4 SCAR=13.9
Pod undocumented
115 2 my $self = shift;
116 2 $self->color_card;
117 2 my $top = $self->color->[0];
118 2 my $float_start = 0;
119 0 ▶ pop @{$self->floats} while @{$self->floats};
Branch: 1 branch
BranchTrueFalseTotal
@{$self->floats;} and do { pop @{$self->floats;} } 0 2 2
120 2 for my $pick (1 .. $self->number_of_turns-1)
121 {
122 18 ▶ next if $self->color->[$pick] == $top;
Branch: 1 branch
BranchTrueFalseTotal
if $self->color->[$pick] == $top 3 15 18
123 15 push @{$self->floats}, [ $float_start, $pick ];
124 15 $top = $self->color->[$pick];
125 15 $float_start = $pick;
126 }
127 2 push @{$self->floats}, [ $float_start, $self->number_of_turns ];
128 }
129
130 4 __PACKAGE__->meta->make_immutable;
131 4 1;
« lib/Weaving/Tablet/Twill/Card.pm ↑ Summary lib/Weaving/snartemo.pl »