TextMode/Writer/ANSI.pm

filter: Statementstmt 93.9% 31 / 33 Branchbran 70.0% 7 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.0% 43 / 50 CC 9 SCAR 16.8
CC
9
Cov
87%
_write
7.6
_gen_args
3.0
BEGIN
1.0
CRAP 5.4
« TextMode/Writer/ANSIMation.pm ↑ Summary TextMode/Writer/XBin.pm »
1 package Image::TextMode::Writer::ANSI;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use charnames ':full';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 extends 'Image::TextMode::Writer';
7  
8 sub _write {
9 1 ▶ my ( $self, $image, $fh, $options ) = @_;
Subroutine _write: called CC=7 SCAR=20.3
10 1 my ( $width, $height ) = $image->dimensions;
11  
12 # clear screen
13 1 print $fh "\N{ESCAPE}[2J";
14  
15 1 my $prevattr = '';
16 1 for my $y ( 0 .. $height - 1 ) {
17 1 my $max_x = $image->max_x( $y );
18  
19 1 ▶ unless ( defined $max_x ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $max_x) 0 1 1
20 0 print $fh "\n";
21 0 next;
22 }
23  
24 1 for my $x ( 0 .. $max_x ) {
25 4 ▶ my $pixel = $image->getpixel( $x, $y )
Condition50%1/2
$image->getpixel($x, $y) || {'char', ' ', 'attr', 7}
l!l
40
MC/DC0%0/1
$image->getpixel($x, $y) || {'char', ' ', 'attr', 7}
$image->getpixel($x, $y)
Truth table50%1/2
A
A= $image->getpixel($x, $y)
Aresult
11
00
26 || { char => ' ', attr => 7 };
27 4 my $attr = _gen_args( $pixel->{ attr } );
28 4 ▶ if ( $attr ne $prevattr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr ne $prevattr) 4 0 4
29 4 print $fh "\N{ESCAPE}[0;", _gen_args( $pixel->{ attr } ), 'm';
30 4 $prevattr = $attr;
31 }
32 4 print $fh $pixel->{ char };
33 }
34 1 ▶ print $fh "\n" unless $max_x == 79;
Branch: 1 branch
BranchTrueFalseTotal
unless $max_x == 79 1 0 1
35 }
36  
37 # clear attrs
38 1 print $fh "\N{ESCAPE}[0m";
39 }
40  
41 sub _gen_args {
42 8 ▶ my $attr = shift;
Subroutine _gen_args: called CC=3 SCAR=11.0
43 8 my $fg = 30 + ( $attr & 7 );
44 8 my $bg = 40 + ( ( $attr & 112 ) >> 4 );
45 8 ▶ my $bl = ( $attr & 128 ) ? 5 : '';
Branch: 1 branch
BranchTrueFalseTotal
$attr & 128 ? : 2 6 8
46 8 ▶ my $in = ( $attr & 8 ) ? 1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$attr & 8 ? : 4 4 8
47 8 return join( q{;}, grep { length } ( $bl, $in, $fg, $bg ) );
48 }
49  
50 =head1 NAME
51  
52 Image::TextMode::Writer::ANSI - Writes ANSI files
53  
54 =head1 DESCRIPTION
55  
56 Provides writing capabilities for the ANSI format.
57  
58 =head1 AUTHOR
59  
60 Brian Cassidy E<lt>bricas@cpan.orgE<gt>
61  
62 =head1 COPYRIGHT AND LICENSE
63  
64 Copyright 2008-2014 by Brian Cassidy
65  
66 This library is free software; you can redistribute it and/or modify
67 it under the same terms as Perl itself.
68  
69 =cut
70  
71 1 1;
« TextMode/Writer/ANSIMation.pm ↑ Summary TextMode/Writer/XBin.pm »