Text/Cmd.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 96 CC 7 SCAR 33.7
CC
7
Cov
0%
callback
56.0
callback_list
2.0
BEGIN
2.0
CRAP 29.0
1 package Ascii::Text::Cmd;
2  
3 use strict;
4 use warnings;
5  
6 use Rope::Cmd;
7 use Types::Standard qw/Str Int Bool Enum/;
8 use Ascii::Text;
9 use Module::Load;
10  
11 colors (
12 title => 'bright_green',
13 abstract => 'bright_red',
14 options_title => 'bright_magenta',
15 options => 'bright_cyan',
16 options_description => 'bright_yellow'
17 );
18  
19 title(Ascii::Text->new( font => 'Poison', align => 'center')->stringify('Ascii Text', 1));
20  
21 abstract 'script for generating ASCII text in various fonts and styles';
22
23 option text => (
24 type => Str,
25 description => "text to print",
26 option_alias => 't',
27 value => "Hello World"
28 );
29  
30 option pad => (
31 type => Int,
32 description => "left padding of the text.",
33 option_alias => 'p',
34 value => 0
35 );
36  
37 option align => (
38 type => Enum[qw( left center right )],
39 description => "alignment of the text. options are left, center or right.",
40 option_alias => 'a',
41 value => "left"
42 );
43  
44 option color => (
45 type => Enum[qw( black red green yellow blue magenta cyan white bright_black bright_red bright_green bright_yellow bright_blue bright_magenta bright_cyan bright_white )],
46 description => "color of the text. options are black, red, green, yellow, blue, magenta, cyan, white, bright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan and bright_white.",
47 option_alias => 'c',
48 );
49  
50 option font => (
51 type => Str,
52 description => "font of the text.",
53 option_alias => 'f',
54 value => 'Boomer'
55 );
56  
57 option fh => (
58 type => Str,
59 description => 'file to write the ascii text to',
60 );
61  
62 option list => (
63 type => Bool,
64 description => 'List all available fonts',
65 option_alias => 'l',
66 value => 0
67 );
68  
69 option all => (
70 type => Bool,
71 description => 'Print out in all available fonts'
72  
73 );
74  
75  
76 option image => (
77 type => Bool,
78 description => 'write the ascii text to an image, used in conjunction with fh and imager_font.',
79 option_alias => 'i',
80 value => 0
81 );
82  
83 option imager_font => (
84 type => Str,
85 description => 'path to imager ttf font',
86 option_alias => 'if',
87 );
88  
89 sub callback {
90 my ($self) = @_;
91 my $fh;
92 return $self->callback_list if ($self->list);
93 my $class = 'Ascii::Text';
94 if ($self->image) {
95 $class = 'Ascii::Text::Image';
96 }
97 load($class);
98 if (!$self->image && $self->fh) {
99 open $fh, '>', $self->fh or die $!;
100 }
101 my $ascii = $class->new(
102 align => $self->align,
103 color => $self->color,
104 pad => $self->pad,
105 font => ucfirst($self->font),
106 imager_font => $self->imager_font,
107 ($fh ? (fh => $fh) : ()),
108 );
109 $ascii->($self->text, ($self->image ? ($self->fh, 1) : ()));
110 if (!$self->image && $self->fh) {
111 close $fh;
112 }
113 }
114  
115 sub callback_list {
116 my ($self) = @_;
117  
118 my $base_path = __FILE__;
119 $base_path =~ s/(.*Text[\/\\])(.*)/$1/;
120 $base_path .= 'Font';
121
122 opendir my $dir, $base_path or die $!;
123 my @files = grep { $_ !~ s/\.pm//; $_ !~ m/^\./ } readdir $dir;
124 closedir $dir;
125  
126 $self->print_color('bright_green', "You have the following fonts installed \n");
127 for (@files) {
128 $self->print_color('bright_cyan', "- $_\n");
129 }
130 }
131  
132 1;