blib/lib/Text/Banner.pm

filter: Statementstmt 100% 124 / 124 Branchbran 100% 32 / 32 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 6 / 6 totaltotal 100% 182 / 182 CC 32 SCAR 16.7
CC
32
Cov
100%
get
9.0
new
6.0
set
5.0
CRAP 5.3
↑ Summary
1  
2 package Text::Banner;
3  
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 our $VERSION = '2.01';
8  
9 9 my $data;
10 my $XL;
11  
12 12 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
13 12 ▶ my $proto=shift; my $class=ref($proto)||$proto;
Condition100%3/3
ref $proto || $proto
l!l&&r!l&&!r
1101
MC/DC100%2/2
ref $proto || $proto
ref $proto $proto
Truth table100%3/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
14 12 my $self={}; my $save=$/; undef $/; my ($byte,$var,$num);
15 12 ▶ unless (defined $XL) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $XL) 9 3 12
16 9 foreach $byte (split //,unpack("u*", $data)) {
17 5238 $var=ord $byte;
18 5238 foreach $num (128,64,32,16,8,4,2,1) {
19 41904 ▶ if (($var&$num)==$num) { $XL .=1; } else { $XL .=0; }
Branch: 1 branch
BranchTrueFalseTotal
if (($var & $num) == $num) { } 12816 29088 41904
20 }
21 }
22 }
23 12 $self->{ORIENTATION}="H"; $self->{SIZE}=1; $/=$save;
24 12 return bless $self,$class;
25 }
26 6 ▶sub rotate {
Subroutine rotate: called CC=4 SCAR=13.9
Pod documented
27 6 my $self=shift;
28 6 ▶ return $self->{ORIENTATION} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 5 6
29 5 my $direction=shift;
30 5 ▶ return undef unless ($direction=~/^h|v/i);
Branch: 1 branch
BranchTrueFalseTotal
unless $direction =~ /^h|v/i 1 4 5
31 4 ▶ if ($direction=~/h/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($direction =~ /h/i) { } 2 2 4
32 2 $self->{ORIENTATION}="H";
33 } else {
34 2 $self->{ORIENTATION}="V";
35 }
36 4 return $self->{ORIENTATION};
37 }
38 9 ▶sub size {
Subroutine size: called CC=4 SCAR=13.9
Pod documented
39 9 my $self=shift;
40 9 ▶ return $self->{SIZE} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 8 9
41 8 my $size=shift;
42 # Allow up to 5x blowup. After that its too grainy to be of decent use.
43 8 ▶ return undef unless ($size > 0 && $size <6);
Branch: 1 branch
BranchTrueFalseTotal
unless $size > 0 and $size < 6 2 6 8
Condition100%3/3
$size > 0 and $size < 6
!ll&&!rl&&r
116
MC/DC100%2/2
$size > 0 and $size < 6
$size > 0 $size < 6
Truth table100%3/3
A and B
A= $size > 0B= $size < 6
ABresult
0X0
100
111
44 6 $self->{SIZE}=$size;
45 6 return $size;
46 }
47 16 ▶sub fill {
Subroutine fill: called CC=4 SCAR=13.9
Pod documented
48 16 my $self=shift;
49 16 ▶ return $self->{FILL} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 15 16
50 15 my $char=shift;
51 15 ▶ if ($char=~/reset/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /reset/i) 1 14 15
52 1 undef $self->{FILL};
53 1 return undef;
54 }
55 14 $char=substr($char,0,1); # only one character allowed for fill value.
56 14 $char=~s/[^\x20-\x7f]+//g;
57 14 ▶ $self->{FILL}=$char if length $char;
Branch: 1 branch
BranchTrueFalseTotal
if length $char 13 1 14
58 14 return $self->{FILL};
59 }
60 17 ▶sub _CHANGE {
Subroutine _CHANGE: called CC=4 SCAR=13.9
61 17 my $self=shift; my $char;
62 17 foreach $char (keys %{$self->{PIC}}) {
63 41 foreach (@{$self->{PIC}->{$char}}) {
64 369 s/0/ /g;
65 369 ▶ if (defined $self->{FILL}) { s/[^\s]|1/$self->{FILL}/g; } else { s/[^\s]/$char/g; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'FILL'}) { } 306 63 369
66 }
67 }
68 }
69 16 ▶sub set {
Subroutine set: called CC=5 SCAR=16.1
Pod documented
70 16 my $self=shift; my $string=shift; my ($char,$var,$pos,$temp,%map);
71 16 ▶ return undef unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 1 15 16
72 15 undef @{$self->{STRING}};
73 15 undef $self->{PIC};
74 15 $string=~s/[^\x20-\x7f]+//g; # We only print ASCII characters 32 to 126. Strip out anything else.
75 15 @{$self->{STRING}}=split'',$string;
76 15 foreach (@{$self->{STRING}}) { $map{$_}=1 };
77 15 foreach $char (keys %map) {
78 35 $var=ord $char; $var-=32; $pos=$var*49;
79 35 $temp=substr($XL,$pos,49);
80 35 foreach (0,7,14,21,28,35,42,49) { push @{$self->{PIC}->{$char}}, substr($temp,$_,7); }
81 35 push @{$self->{PIC}->{$char}},"0000000"; # this is spacing between lines
82 }
83 15 return undef;
84 }
85 9 ▶sub _BLOWUP {
Subroutine _BLOWUP: called CC=3 SCAR=11.0
86 9 my $self=shift; my ($dynamic,$output,$temp);
87 9 $dynamic='$self->{CURRENT_LINE}=~s/(.)/'.'$1' x $self->{SIZE}.'/mg;';
88 9 eval $dynamic;
89 9 ▶ if ($self->{ORIENTATION}=~/H/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ORIENTATION'} =~ /H/i) { } 8 1 9
90 8 $temp=$self->{CURRENT_LINE};
91 8 $dynamic='$output .="'. '$temp\n' x $self->{SIZE}.'";';
92 8 eval $dynamic;
93 } else {
94 1 foreach (split /\n/,$self->{CURRENT_LINE}) {
95 14 $dynamic='$output .= "'.'$_\n' x $self->{SIZE}.'";';
96 14 eval $dynamic;
97 }
98 }
99 9 return $output;
100 }
101 17 ▶sub get {
Subroutine get: called CC=9 SCAR=22.0
Pod documented
102 17 my $self=shift; my ($creation,$num,$char,$line,$pos,$temp);
103 17 $self->_CHANGE;
104 17 ▶ if ($self->{ORIENTATION}=~/h/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ORIENTATION'} =~ /h/i) { } 15 2 17
105 15 foreach $num (0..7) {
106 120 undef $self->{CURRENT_LINE};
107 120 foreach (@{$self->{STRING}}) { $self->{CURRENT_LINE} .=${$self->{PIC}->{$_}}[$num]." "; }
108 120 ▶ if ($self->{SIZE}>1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'SIZE'} > 1) { } 8 112 120
109 8 $creation .=$self->_BLOWUP;
110 } else {
111 112 $creation .=$self->{CURRENT_LINE}."\n";
112 }
113 }
114 } else {
115 2 foreach $char (@{$self->{STRING}}) {
116 5 my @array=@{$self->{PIC}->{$char}};
117 5 undef $self->{CURRENT_LINE};
118 5 foreach $pos (0..6) {
119 35 foreach $line (6,5,4,3,2,1,0) { $self->{CURRENT_LINE}.=substr($array[$line],$pos,1); }
120 35 $self->{CURRENT_LINE}.="\n";
121 }
122 5 $creation .=$self->{CURRENT_LINE};
123 }
124 2 ▶ if ($self->{SIZE}>1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"SIZE"} > 1) 1 1 2
125 1 $self->{CURRENT_LINE}=$creation;
126 1 $creation=$self->_BLOWUP;
127 }
128 }
129 17 return $creation;
130 }
131  
132  
133 9 $data = <<'EOF';
134 M````````'#AP0`.'._=$````!0I_*?RA1])D/A,E]QI=!!=+',)##B+"<G#@
135 M@@```!A!`@0$!A@("!`@A@`B*?RB(``$"'P@0````!PX((```!\````````.
136 M'#@$$$$$$$`XB@P8*(X(,*!`@0^?00+Z!`_OH(%\!@OH$*%"_@@7^!`_`8+Y
137 M]!@?H,%]_A!!!`@0?08+Z#!?/H,%^!@OA!P0`$'!!PX`.'!!`(((("`@(``/
138 M@#X``("`@((((/H($<(`"'T&[=O0'P@HB@_X,']!@_H,'\^@P($""^_08,&#
139 M!_?X$#Y`@?_\"!\@0(#Z#`GP8+Z#!@_X,&"<$"!`@0<`@0(&#!?0HDCA(B0H
140 M$"!`@0/\''5DP8,&#AHR8L.#_@P8,&#__08/Z!`@/H,&#%A/?T&#^B0H+Z#`
141 M?`8+[^($"!`@1!@P8,&"^@P8,%$4$09,F3)DMH*(H(*(H,%$4$"!`C^"""""
142 M#^^0($"!`^@("`@("`O@0($"!/A!1$```````````'\X<$!`````&$D+]"A`
143 M/D+Y"A?`#R%`@0G@#Y"A0H7P!^@?($#\`_0/D"!``/(4"=">`(4+]"A0@`@0
144 M($"!``$"!`H3P!"B>)$2$`@0($"!^`0LUJ%"A`(6*E*C0@#R%"A0G@#Y"A?(
145 M$``\A0I41T`^0H7R)"`/(#P%">`'P@0($"`$*%"A0G@"%"A0DA@!"A0K6:$`
146 JA)#!A)"`(B@@0($`/P0000?G$"#`@0'!`@0`$"!!P$"!@@1QA)#`````
147 EOF
148  
149 9 1;
150  
151  
152 =head1 NAME
153  
154 Text::Banner - Create text resembling Unix banner command
155  
156 =head1 VERSION
157  
158 This document refers to Text::Banner version 2.01.
159  
160 =head1 SYNOPSIS
161  
162 use Text::Banner;
163 my $ban = Text::Banner->new();
164 $ban->set('MYTEXT');
165 $ban->size(3);
166 $ban->fill('*');
167 $ban->rotate('h');
168 print $ban->get();
169  
170 =head1 DESCRIPTION
171  
172 The B<Text::Banner> creates a large ASCII-representation of a defined string, like
173 the 'banner' command available in Unix. A string is passed to the module, and the
174 equivalent banner string is generated and returned for use. The string can be
175 scaled (blown up) from 100 to 500% of the base size. The characters used to
176 generate the banner image can be any character defined by the user (within a
177 limited range) or they can be the made up from whatever the current character
178 being generated happens to be. The banner can be created either vertically or
179 horizontally.
180  
181 =head1 METHODS
182  
183 =head2 new
184  
185 An object reference is created with the B<new> method. The reference is then used
186 to define the string to create and for manipulation of the object. No specific order
187 is required for object manipulation, with the exception of the 'get' operation which
188 will return the string based upon the current object definitions.
189  
190 =head2 set
191  
192 The 'set' operation allows the user to specify the string to be generated.
193 There is no limit on the length of the string; however, generated strings that
194 are longer than the display output will continue onto the next line and
195 interlace with the first character that was generated - resulting in a messy,
196 difficult-to-read output. Some experimentation may be required to find the
197 ideal maximum length depending upon the environment you are using.
198  
199 =head2 size
200  
201 The 'size' operation provides functionality for blowing up the size of the
202 generated string from 100 to 500 percent of normal size. '1' is 100%, '2' is
203 200% and so on. The larger the defined size, the grainier the output
204 string becomes. When an object is first created, the size defaults to '1'.
205 Calling the 'size' method without any parameters will return the current
206 size definition.
207  
208 =head2 rotate
209  
210 The 'rotate' method allows switching between horizontal and vertical output.
211 Objects are created by default in horizontal mode. Calling the method
212 without any arguments will return the current output mode. Otherwise, specify
213 either 'h' for horizontal or 'v' for vertical output.
214  
215 =head2 fill
216  
217 The 'fill' operation defines how the returned string should be created. By
218 default, newly created objects will use the current ASCII character of the
219 character being generated. For example, creating the string 'Hello' without
220 changing the fill character will cause a string to be created where the 'H'
221 is made up of the letter 'H', the 'e' from the letter 'e', 'l' from 'l' and so
222 on. This can be changed if desired by calling the 'fill' operation with the
223 ASCII character you wish all characters of the string to be created from.
224 Once defined, the fill character remains constant until changed again. Calling
225 the fill operation with no parameters will return the currently defined fill
226 character. Calling the fill operation with the command 'reset' will remove the
227 fill character, and default back to the original behaviour as outlined above.
228  
229 =head2 get
230  
231 The 'get' operation is what causes the string to be generated based upon the
232 current object definitions. The object is generated and passed directly back
233 from the method. Therefore, it can either be printed directly or saved to a
234 variable for later use.
235  
236 =head1 EXAMPLES
237  
238 # Example 1:
239  
240 use Text::Banner;
241 my $h = Text::Banner->new();
242 $h->set('MYTEXT');
243 $h->fill('*');
244 foreach my $num (1..5) {
245 $h->size($num);
246 $h->rotate('h');
247 print $h->get();
248 $h->rotate('v');
249 print $h->get();
250 }
251  
252  
253 # Example 2:
254  
255 use Text::Banner;
256 my $h = Text::Banner->new();
257 $h->set('MYtext');
258 print $h->get();
259 $h->fill('/');
260 print $h->get();
261  
262 Example 2 would generate the following output:
263  
264 M M Y Y
265 MM MM Y Y ttttt eeeeee x x ttttt
266 M M M M Y Y t e x x t
267 M M M Y t eeeee xx t
268 M M Y t e xx t
269 M M Y t e x x t
270 M M Y t eeeeee x x t
271  
272 / / / /
273 // // / / ///// ////// / / /////
274 / / / / / / / / / / /
275 / / / / / ///// // /
276 / / / / / // /
277 / / / / / / / /
278 / / / / ////// / / /
279  
280 Consult the horizontal.txt and vertical.txt files that come with the
281 module for examples of what different sizes look like.
282  
283 =head1 NOTES
284  
285 Multiple objects can of course be generated; however, it should be kept in
286 mind that the object is not static and changing the defined string output
287 could be used as an alternative to multiple object creation as each created
288 object chews up about 4k of memory.
289  
290 Generated ASCII characters are restricted to those between 32 (space) and
291 126 (~). Those outside of these values are removed, and the resulting
292 generated string will not include them. The same restriction applies to the
293 fill character used for defining character generation.
294  
295 =head1 AUTHOR
296  
297 The original author is Stuart Lory (CPAN ID: LORY).
298  
299 Gene Sullivan (gsullivan@cpan.org) is a co-maintainer.
300  
301 =head1 COPYRIGHT AND LICENSE
302  
303 Copyright (c) 1999 Stuart Lory. All rights reserved.
304  
305 This module is free software; you can redistribute it and/or modify
306 it under the same terms as Perl itself. See L<perlartistic|perlartistic>.
307  
308 =cut
309  
↑ Summary