File Coverage

blib/lib/Dist/Zilla/dumpphases/Role/Theme/SimpleColor.pm
Criterion Covered Total %
statement 34 35 97.1
branch 1 2 50.0
condition n/a
subroutine 15 15 100.0
pod 3 3 100.0
total 53 55 96.3


line stmt bran cond sub pod time code
1 7     7   41930 use 5.006;
  7         22  
2 7     7   28 use strict;
  7         10  
  7         130  
3 7     7   24 use warnings;
  7         9  
  7         458  
4              
5             package Dist::Zilla::dumpphases::Role::Theme::SimpleColor;
6              
7             our $VERSION = '1.000009';
8              
9             # ABSTRACT: A role for themes that are simple single-color themes with variations of bold/uncolored.
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 7     7   534 use Role::Tiny qw( requires with );
  7         3063  
  7         37  
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27             with 'Dist::Zilla::dumpphases::Role::Theme';
28              
29              
30              
31              
32              
33              
34              
35             requires 'color';
36              
37             ## no critic ( RequireArgUnpacking )
38             sub _colored {
39 102 50   102   2092 require Term::ANSIColor; () = eval { require Win32::Console::ANSI } if 'MSWin32' eq $^O;
  102         13408  
  0         0  
40 102         190 goto \&Term::ANSIColor::colored;
41             }
42              
43             sub _color_label_label {
44 6     6   9 my $self = shift;
45 6         27 return _colored( [ $self->color ], @_ );
46             }
47              
48             sub _color_label_value {
49 6     6   156 shift;
50 6         16 return _colored( ['bold'], @_ );
51             }
52              
53             sub _color_attribute_label {
54 12     12   14 my $self = shift;
55 12         27 return _colored( [ $self->color, 'bold' ], @_ );
56             }
57              
58             sub _color_attribute_value {
59 12     12   255 my $self = shift;
60 12         25 return _colored( [ $self->color ], @_ );
61             }
62              
63             sub _color_plugin_name {
64 33     33   583 shift;
65 33         64 return @_;
66             }
67              
68             sub _color_plugin_package {
69 33     33   28 my $self = shift;
70 33         55 return _colored( [ $self->color ], @_ );
71             }
72              
73             sub _color_plugin_star {
74 33     33   25 my $self = shift;
75 33         67 return _colored( [ $self->color ], @_ );
76             }
77              
78              
79              
80              
81              
82              
83              
84              
85              
86             sub print_section_header {
87 6     6 1 11 my ( $self, $label, $comment ) = @_;
88 6         20 return printf "\n%s%s\n", $self->_color_label_label($label), $self->_color_label_value($comment);
89             }
90              
91              
92              
93              
94              
95              
96              
97              
98              
99             sub print_section_prelude {
100 12     12 1 22 my ( $self, $label, $value ) = @_;
101 12         31 return printf "%s%s\n", $self->_color_attribute_label( ' - ' . $label ), $self->_color_attribute_value($value);
102             }
103              
104              
105              
106              
107              
108              
109              
110              
111              
112             sub print_star_assoc {
113 33     33 1 162 my ( $self, $name, $value ) = @_;
114 33         46 return printf "%s%s%s\n",
115             $self->_color_plugin_star(' * '),
116             $self->_color_plugin_name($name),
117             $self->_color_plugin_package( ' => ' . $value );
118             }
119              
120              
121              
122              
123              
124              
125              
126              
127              
128              
129              
130              
131              
132              
133              
134             1;
135              
136             __END__
137              
138             =pod
139              
140             =encoding UTF-8
141              
142             =head1 NAME
143              
144             Dist::Zilla::dumpphases::Role::Theme::SimpleColor - A role for themes that are simple single-color themes with variations of bold/uncolored.
145              
146             =head1 VERSION
147              
148             version 1.000009
149              
150             =head1 SYNOPSIS
151              
152             package Dist::Zilla::dumpphases::Theme::foo;
153              
154             use Moo;
155             with 'Dist::Zilla::dumpphases::Role::Theme::SimpleColor';
156             sub color { 'magenta' };
157              
158             ...
159              
160             dzil dumpphases --color-theme=foo
161              
162             =begin MetaPOD::JSON v1.1.0
163              
164             {
165             "namespace":"Dist::Zilla::dumpphases::Role::Theme::SimpleColor",
166             "does":"Dist::Zilla::dumpphases::Role::Theme",
167             "interface":"role"
168             }
169              
170              
171             =end MetaPOD::JSON
172              
173             =head1 REQUIRED METHODS
174              
175             =head2 C<color>
176              
177             You must define a method called C<color> that returns a string (or list of strings ) that C<Term::ANSIColor> recognizes.
178              
179             =head1 METHODS
180              
181             =head2 C<print_section_header>
182              
183             See L<Dist::Zilla::dumpphases::Role::Theme/print_section_header>.
184              
185             This satisfies that, printing label colored, and the value uncolored.
186              
187             =head2 C<print_section_prelude>
188              
189             See L<Dist::Zilla::dumpphases::Role::Theme/print_section_prelude>.
190              
191             This satisfies that, printing label bold and colored, and the value simply colored.
192              
193             =head2 C<print_star_assoc>
194              
195             See L<Dist::Zilla::dumpphases::Role::Theme/print_star_assoc>.
196              
197             This satisfies that, printing label uncolored, and the value simply colored.
198              
199             =head1 AUTHOR
200              
201             Kent Fredric <kentnl@cpan.org>
202              
203             =head1 COPYRIGHT AND LICENSE
204              
205             This software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>.
206              
207             This is free software; you can redistribute it and/or modify it under
208             the same terms as the Perl 5 programming language system itself.
209              
210             =cut