| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Text::Twiddler; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
78343
|
use warnings; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
67
|
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
71
|
|
|
5
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
211
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12478
|
use version; our $VERSION = qv('0.0.1'); |
|
|
2
|
|
|
|
|
5206
|
|
|
|
2
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
10875
|
use Class::Std; |
|
|
2
|
|
|
|
|
39273
|
|
|
|
2
|
|
|
|
|
17
|
|
|
10
|
2
|
|
|
2
|
|
2769
|
use Class::Std::Utils; |
|
|
2
|
|
|
|
|
1467
|
|
|
|
2
|
|
|
|
|
14
|
|
|
11
|
2
|
|
|
2
|
|
2021
|
use Locale::Maketext::Pseudo; |
|
|
2
|
|
|
|
|
1780
|
|
|
|
2
|
|
|
|
|
172
|
|
|
12
|
2
|
|
|
2
|
|
2052
|
use List::Cycle; |
|
|
2
|
|
|
|
|
2077
|
|
|
|
2
|
|
|
|
|
624
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
{ |
|
15
|
|
|
|
|
|
|
my %output_ns :ATTR( :get :init_arg :default); |
|
16
|
|
|
|
|
|
|
my %iterations :ATTR( :get ); |
|
17
|
|
|
|
|
|
|
my %longest :ATTR( :get ); |
|
18
|
|
|
|
|
|
|
my %start :ATTR( :get :init_arg :default ); |
|
19
|
|
|
|
|
|
|
my %text :ATTR( :get :init_arg :default ); |
|
20
|
|
|
|
|
|
|
my %end :ATTR( :get :init_arg :default ); |
|
21
|
|
|
|
|
|
|
my %lang :ATTR( :init_arg :default<> ); |
|
22
|
|
|
|
|
|
|
my %sway :ATTR( :init_arg :default<0>); |
|
23
|
|
|
|
|
|
|
my %frames :ATTR( :get ); |
|
24
|
|
|
|
|
|
|
my %cycle; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub START { |
|
27
|
2
|
|
|
2
|
1
|
735
|
my ($self, $ident, $arg_ref) = @_; |
|
28
|
|
|
|
|
|
|
|
|
29
|
2
|
50
|
33
|
|
|
19
|
$lang{ $ident } = ref $arg_ref->{'lang_obj'} && $arg_ref->{'lang_obj'}->can('maketext') |
|
30
|
|
|
|
|
|
|
? $arg_ref->{'lang_obj'} : Locale::Maketext::Pseudo->new(); |
|
31
|
|
|
|
|
|
|
|
|
32
|
2
|
100
|
|
|
|
34
|
if( $arg_ref->{'output_ns'} ) { |
|
33
|
1
|
50
|
33
|
|
|
11
|
if( $arg_ref->{'output_ns'}->can('get_output_pre') |
|
|
|
|
33
|
|
|
|
|
|
34
|
|
|
|
|
|
|
&& $arg_ref->{'output_ns'}->can('get_output_str') |
|
35
|
|
|
|
|
|
|
&& $arg_ref->{'output_ns'}->can('get_output_pst') |
|
36
|
|
|
|
|
|
|
) { |
|
37
|
1
|
|
|
|
|
35
|
$output_ns{ $ident } = $arg_ref->{'output_ns'}; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
else { |
|
40
|
0
|
|
|
|
|
0
|
carp $lang{ $ident }->maketext( q{'[_1]' does not have required '[_2]' method, defaulting to '[_3]'}, 'output_ns', 'get_output_*', $output_ns{ $ident } ); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
{ |
|
45
|
|
|
|
|
|
|
# just in case someone's turned on bytes... |
|
46
|
2
|
|
|
2
|
|
2699
|
no bytes; |
|
|
2
|
|
|
|
|
22
|
|
|
|
2
|
|
|
|
|
12
|
|
|
|
2
|
|
|
|
|
4
|
|
|
47
|
2
|
100
|
|
|
|
7
|
$longest{ $ident } = length( $start{ $ident } ) >= length( $end{ $ident } ) ? length( $start{ $ident } ) : length( $end{ $ident } ); |
|
48
|
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
3
|
my $twiddle_me_this = []; |
|
50
|
2
|
50
|
|
|
|
10
|
if ( ref $text{ $ident } eq 'ARRAY' ) { |
|
51
|
0
|
0
|
|
|
|
0
|
if ( @{ $text{ $ident } } > 1 ) { |
|
|
0
|
|
|
|
|
0
|
|
|
52
|
0
|
|
|
|
|
0
|
@{ $twiddle_me_this } = @{ $text{ $ident } }; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
53
|
0
|
|
|
|
|
0
|
$text{ $ident } = [sort { length($b) <=> length($a) } @{ $twiddle_me_this } ]->[0]; # assign this the longest for length() calc below |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
else { |
|
56
|
0
|
|
|
|
|
0
|
$text{ $ident } = $text{ $ident }->[0]; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
2
|
50
|
|
|
|
5
|
$longest{ $ident } = length( $text{ $ident } ) if length( $text{ $ident } ) > $longest{ $ident }; |
|
61
|
2
|
|
|
|
|
5
|
$iterations{ $ident } = $longest{ $ident }; |
|
62
|
|
|
|
|
|
|
|
|
63
|
2
|
50
|
|
|
|
3
|
if ( !@{ $twiddle_me_this } ) { |
|
|
2
|
|
|
|
|
5
|
|
|
64
|
2
|
|
|
|
|
6
|
$twiddle_me_this = Text::Twiddler::FX::standard($text{ $ident }) |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
2
|
100
|
|
|
|
6
|
if ($sway{ $ident}) { |
|
68
|
1
|
50
|
|
|
|
3
|
push @{ $twiddle_me_this }, reverse @{ $twiddle_me_this } if $sway{ $ident }; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
3
|
|
|
69
|
1
|
|
|
|
|
3
|
$iterations{ $ident } *= 2; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
4
|
@{ $frames{ $ident } } = @{ $twiddle_me_this }; # copy array, do not assign same ref |
|
|
2
|
|
|
|
|
18
|
|
|
|
2
|
|
|
|
|
2
|
|
|
73
|
2
|
|
|
|
|
14
|
$cycle{ $ident } = List::Cycle->new({ 'values' => $twiddle_me_this }); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_start_twiddler { |
|
78
|
2
|
|
|
2
|
1
|
4555
|
my ($self) = @_; |
|
79
|
2
|
|
|
|
|
15
|
$| = 1; # TODO: this more robust or localized |
|
80
|
2
|
|
|
|
|
6
|
return $self->get_output_pre() . $self->get_output_str( $self->get_start() ); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get_next_twiddler { |
|
84
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
85
|
0
|
|
|
|
|
0
|
return $self->get_output_str( $self->get_next_frame() ); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get_next_frame { |
|
89
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
90
|
0
|
|
|
|
|
0
|
return $cycle{ ident $self }->next(); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub get_end_twiddler { |
|
94
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
95
|
0
|
|
|
|
|
0
|
return $self->get_output_str( $self->get_end() ) . $self->get_output_pst(); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub get_uniq_str { |
|
99
|
3
|
|
|
3
|
1
|
50
|
my ($self) = @_; |
|
100
|
3
|
|
|
|
|
19
|
return ref($self) . '-' . ident($self); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub get_output_pre { |
|
104
|
2
|
|
|
2
|
1
|
3
|
my ($self) = @_; |
|
105
|
2
|
|
|
|
|
16
|
return $output_ns{ ident $self }->get_output_pre( $self ); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub get_output_str { |
|
109
|
2
|
|
|
2
|
1
|
10
|
my ($self, $string) = @_; |
|
110
|
2
|
|
|
|
|
9
|
return $output_ns{ ident $self }->get_output_str( $self, $string ); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub get_output_pst { |
|
114
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
115
|
0
|
|
|
|
|
0
|
return $output_ns{ ident $self }->get_output_pst( $self ); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub get_blank_twiddler { |
|
119
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
120
|
0
|
|
|
|
|
0
|
return $self->get_output_str('') . $self->get_output_pst(); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
package Text::Twiddler::HTML; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub get_output_pre { |
|
127
|
1
|
|
|
1
|
|
2
|
my ( $output_ns, $twid ) = @_; |
|
128
|
1
|
|
|
|
|
4
|
my $id = $twid->get_uniq_str(); |
|
129
|
1
|
|
|
|
|
5
|
return qq{\n}; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub get_output_str { |
|
133
|
1
|
|
|
1
|
|
3
|
my ( $output_ns, $twid, $string ) = @_; |
|
134
|
1
|
|
|
|
|
3
|
my $id = $twid->get_uniq_str(); |
|
135
|
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
993
|
require HTML::Entities; |
|
137
|
1
|
|
|
|
|
10053
|
$string = HTML::Entities::encode( $string ); |
|
138
|
|
|
|
|
|
|
|
|
139
|
1
|
|
|
|
|
34
|
return qq{\n}; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub get_output_pst { |
|
143
|
0
|
|
|
0
|
|
0
|
my ( $output_ns, $twid ) = @_; |
|
144
|
0
|
|
|
|
|
0
|
return ''; # no-op since in HTML since we always write to the same div |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
package Text::Twiddler::CLI; |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub get_output_pre { |
|
150
|
1
|
|
|
1
|
|
1
|
my ( $output_ns, $twid ) = @_; |
|
151
|
1
|
|
|
|
|
5
|
return ''; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub get_output_str { |
|
155
|
1
|
|
|
1
|
|
2
|
my ( $output_ns, $twid, $string ) = @_; |
|
156
|
1
|
|
|
|
|
3
|
my $len = $twid->get_longest(); |
|
157
|
1
|
|
|
|
|
4
|
my $bs = ''; |
|
158
|
|
|
|
|
|
|
|
|
159
|
1
|
50
|
|
|
|
3
|
if( $string ne $twid->get_start() ) { |
|
160
|
0
|
|
|
|
|
0
|
$bs = "\b" x $len; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
1
|
|
|
|
|
15
|
return $bs . sprintf('%-' . $len .'s', $string); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub get_output_pst { |
|
167
|
0
|
|
|
0
|
|
0
|
my ( $output_ns, $twid ) = @_; |
|
168
|
0
|
|
|
|
|
0
|
return "\n"; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
package Text::Twiddler::FX; |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub standard { |
|
174
|
2
|
|
|
2
|
|
2
|
my ($string) = @_; |
|
175
|
|
|
|
|
|
|
|
|
176
|
2
|
|
|
|
|
2
|
my @twiddle_me_this; |
|
177
|
2
|
|
|
|
|
13
|
my @letters = split '', $string; |
|
178
|
2
|
|
|
|
|
7
|
for my $lidx ( 0 .. $#letters ) { |
|
179
|
26
|
|
|
|
|
23
|
my $part = $letters[0]; |
|
180
|
26
|
|
|
|
|
27
|
for my $nxt ( 1 .. $lidx ) { |
|
181
|
165
|
|
|
|
|
153
|
$part .= $letters[$nxt]; |
|
182
|
|
|
|
|
|
|
} |
|
183
|
26
|
|
|
|
|
59
|
push @twiddle_me_this, $part; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
2
|
|
|
|
|
6
|
return \@twiddle_me_this; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub secret_decoder { |
|
190
|
0
|
|
|
0
|
|
|
my ($string) = @_; |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
my @twiddle_me_this; |
|
193
|
0
|
|
|
|
|
|
my @letters = split '', $string; |
|
194
|
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
return \@twiddle_me_this; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
__END__ |