File Coverage

blib/lib/Image/TextMode/Reader/Bin.pm
Criterion Covered Total %
statement 16 19 84.2
branch 3 6 50.0
condition 2 5 40.0
subroutine 2 2 100.0
pod n/a
total 23 32 71.8


line stmt bran cond sub pod time code
1             package Image::TextMode::Reader::Bin;
2              
3 2     2   1248 use Moo;
  2         4  
  2         14  
4              
5             extends 'Image::TextMode::Reader';
6              
7             sub _read {
8 2     2   5 my ( $self, $image, $fh, $options ) = @_;
9              
10 2 50       43 if ( $image->has_sauce ) {
11 0         0 $image->render_options->{ blink_mode } = $image->sauce->flags_id ^ 1;
12             }
13              
14 2   50     114 my $width = $options->{ width } || 160;
15 2         5 my ( $x, $y ) = ( 0, 0 );
16 2         4 my $eof = chr( 26 );
17 2         4 my $chardata;
18 2         50 while ( read( $fh, $chardata, 2 ) ) {
19 8         34 my @data = unpack( 'aC', $chardata );
20 8 50 33     40 last if tell( $fh ) > $options->{ filesize } || $data[ 0 ] eq $eof;
21 8         47 $image->putpixel( { char => $data[ 0 ], attr => $data[ 1 ] }, $x,
22             $y );
23              
24 8         323 $x++;
25 8 50       41 if ( $x == $width ) {
26 0         0 $x = 0;
27 0         0 $y++;
28             }
29             }
30              
31 2         34 return $image;
32             }
33              
34             =head1 NAME
35              
36             Image::TextMode::Reader::Bin - Reads Bin files
37              
38             =head1 DESCRIPTION
39              
40             Provides reading capabilities for the Bin format.
41              
42             =head1 AUTHOR
43              
44             Brian Cassidy Ebricas@cpan.orgE
45              
46             =head1 COPYRIGHT AND LICENSE
47              
48             Copyright 2008-2014 by Brian Cassidy
49              
50             This library is free software; you can redistribute it and/or modify
51             it under the same terms as Perl itself.
52              
53             =cut
54              
55             1;