Colorist.pm

filter: Statementstmt 50.0% 20 / 40 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 1 totaltotal 38.9% 23 / 59 CC 6 SCAR 21.4
CC
6
Cov
40%
_build__colorizer
20.0
_build_configuration
6.0
_build_execute
6.0
CRAP 8.5
↑ Summary Colorist/Colorizer.pm »
1 package App::Colorist;
2 1 $App::Colorist::VERSION = '0.150460';
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 with 'MooseX::Getopt';
6  
7 1 ▶use App::Colorist::Colorizer;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use IPC::Open3;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # ABSTRACT: Add color to your plain old outputs
12  
13  
14 1 has configuration => (
15 is => 'ro',
16 isa => 'Str',
17 traits => [ 'Getopt' ],
18 cmd_aliases => [ qw(c) ],
19 lazy_build => 1,
20 );
21  
22 0 ▶sub _build_configuration {
Subroutine _build_configuration: not called CC=2 SCAR=17.9
23 0 my $self = shift;
24  
25 0 ▶ return $self->extra_argv->[0] if $self->execute;
Branch: 1 branch
BranchTrueFalseTotal
if $self->execute 0 0 0
26 0 return;
27 }
28  
29 1 has ruleset => (
30 is => 'ro',
31 isa => 'Str',
32 required => 1,
33 traits => [ 'Getopt' ],
34 cmd_aliases => [ qw(R) ],
35 default => 'rules',
36 );
37  
38 1 has colorset => (
39 is => 'ro',
40 isa => 'Str',
41 required => 1,
42 traits => [ 'Getopt' ],
43 cmd_aliases => [ qw(C) ],
44 default => 'colors',
45 );
46  
47 has include => (
48 is => 'ro',
49 isa => 'ArrayRef',
50 required => 1,
51 traits => [ 'Getopt' ],
52 cmd_aliases => [ qw(I) ],
53 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 1 );
55  
56 1 has debug => (
57 is => 'ro',
58 isa => 'Bool',
59 required => 1,
60 default => 0,
61 );
62  
63 1 has execute => (
64 is => 'ro',
65 isa => 'Bool',
66 traits => [ 'Getopt' ],
67 cmd_aliases => [ qw(e) ],
68 lazy_build => 1,
69 );
70  
71 0 ▶sub _build_execute {
Subroutine _build_execute: not called CC=2 SCAR=17.9
72 0 my $self = shift;
73 0 ▶ return $self->stderr ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->stderr ? : 0 0 0
74 }
75  
76 1 has stderr => (
77 is => 'ro',
78 isa => 'Bool',
79 required => 1,
80 traits => [ 'Getopt' ],
81 cmd_aliases => [ qw(E) ],
82 default => 0,
83 );
84  
85 # I would like to have this someday...
86 # has follow => (
87 # is => 'ro',
88 # isa => 'Bool',
89 # required => 1,
90 # default => 0,
91 # );
92  
93 1 has _colorizer => (
94 reader => 'colorizer',
95 isa => 'App::Colorist::Colorizer',
96 lazy_build => 1,
97 handles => [ 'run' ],
98 );
99  
100 0 ▶sub _build__colorizer {
Subroutine _build__colorizer: not called CC=4 SCAR=30.0
101 0 my $self = shift;
102  
103 0 my @args = @{ $self->extra_argv };
104  
105 0 my %params;
106  
107 # The command-line contains the command to run and arguments to it
108 0 ▶ if ($self->execute) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->execute) 0 0 0
109  
110 # They have asked us to capture STDERR too
111 0 ▶ if ($self->stderr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->stderr) { } 0 0 0
112 0 open3('<&STDIN', my $outfh, my $errfh, @args);
113 0 $params{inputs} = [ $outfh, $errfh ];
114 }
115  
116 # They have asked us to capture just STDOUT
117 else {
118 0 ▶ open my $fh, '-|', @args or die "cannot execute ", join(' ', @args), ": ", $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "-|", @args or die "cannot execute ", join(" ", @args), ": ", $! 0 0 0
119 0 $params{inputs} = [ $fh ];
120 }
121 }
122  
123 # Otherwise, we use the default input reading from ARGV
124  
125 0 return App::Colorist::Colorizer->new(
126 configuration => $self->configuration,
127 ruleset => $self->ruleset,
128 colorset => $self->colorset,
129 include => $self->include,
130 debug => $self->debug,
131 %params,
132 );
133 }
134  
135 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
136 0 my $self = shift;
137  
138 # This makes sure that <ARGV> works
139 0 @ARGV = @{ $self->extra_argv };
140 }
141  
142  
143 1 __PACKAGE__->meta->make_immutable;
144  
145 __END__
↑ Summary Colorist/Colorizer.pm »