lib/Weaving/Tablet/Twill.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
« lib/Weaving/Tablet/Tk.pm ↑ Summary
1 package Weaving::Tablet::Twill;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 use namespace::autoclean
5 use Carp;
6  
7 extends 'Weaving::Tablet';
8  
9 our $VERSION = '0.009.004';
10  
11 sub BUILD
12 {
13 my $self = shift;
14 if ( defined $self->file_name )
15 {
16 $self->load_pattern;
17 return;
18 }
19 push @{ $self->cards },
20 Weaving::Tablet::Twill::Card->new(
21 number_of_turns => $self->pattern_length,
22 offset => $_ % 2
23 ) for 1 .. $self->number_of_cards;
24 }
25  
26 sub load_pattern
27 {
28 my $self = shift;
29  
30 return 0 unless defined $self->file_name;
31 return 0 unless -r $self->file_name;
32 open my $pattern, '<', $self->file_name
33 or croak "Can't open " . $self->file_name . ": $!";
34 my ( $cards, $rows, $holes ) = ( split( / /, <$pattern> ) )[ 0, 2, 4 ];
35 $holes ||= 4;
36 $self->number_of_cards($cards);
37 $self->_set_number_of_holes($holes);
38  
39 # prime cards with empty cards
40 push @{ $self->cards },
41 Weaving::Tablet::Twill::Card->new( number_of_turns => 0 )
42 for 1 .. $self->number_of_cards;
43  
44 my $card;
45 while (<$pattern>)
46 {
47 chomp;
48 last unless /^[\\\/|]/;
49 $self->insert_pick( [ -1, $_ ] );
50 }
51  
52 # now $_ contains the start line...
53 tr /ABCDEFGH/01234567/;
54 my @starts = split( //, $_ );
55 for my $card ( 0 .. $self->number_of_cards - 1 )
56 {
57 $self->cards->[$card]->start( $starts[$card] );
58 }
59  
60 $_ = <$pattern>;
61 chomp;
62 my @SZ = split( //, $_ );
63 for my $card ( 0 .. $self->number_of_cards - 1 )
64 {
65 $self->cards->[$card]->SZ( $SZ[$card] );
66 }
67  
68 for my $card ( 0 .. $self->number_of_cards - 1 )
69 {
70 $_ = <$pattern>;
71 chomp;
72 $self->cards->[$card]->set_threading( [ split( /,/, $_ ) ] );
73 }
74  
75 pop @{ $self->color_table } while @{ $self->color_table };
76 while (<$pattern>)
77 {
78 chomp;
79 push @{ $self->color_table }, $_; # use X color names here
80 }
81  
82 close $pattern;
83  
84 $self->color_pattern;
85 $self->initialize_cells;
86 $self->twist_pattern;
87 $self->dirty(0);
88 1;
89 }
90  
91 sub initialize_cells
92 {
93 my $self = shift;
94 for my $card (@{$self->cards})
95 {
96 $card->initialize_cells;
97 }
98 }
99  
100 __PACKAGE__->meta->make_immutable
101 1;
102 __END__
« lib/Weaving/Tablet/Tk.pm ↑ Summary