Writer.pm

filter: Statementstmt 43.5% 17 / 39 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 5 / 10 Podpod 40.0% 2 / 5 totaltotal 35.2% 24 / 68 CC 6 SCAR 18.2
CC
6
Cov
34%
new
12.0
write
12.0
set_input
6.0
CRAP 6.2
↑ Summary Reader.pm »
1 package Text::Annotated::Writer;
2 # $Id: Writer.pm,v 1.7 2007-05-12 18:39:16 wim Exp $
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Text::Annotated::Line;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Text::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use base qw(Text::Filter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 $VERSION = '0.04';
9  
10 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
11 0 my $proto = shift;
12 0 ▶ my $pkg = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
13 0 my %arg = @_;
14  
15 # initialize the no_annotation flag
16 0 ▶ my $no_annotation = $arg{no_annotation} || 0; # defaults to printing of the annotations
Condition0%0/2
$arg{'no_annotation'} || 0
l!l
00
MC/DC0%0/1
$arg{'no_annotation'} || 0
$arg{'no_annotation'}
Truth table0%0/2
A
A= $arg{'no_annotation'}
Aresult
11
00
17 0 delete $arg{no_annotation};
18  
19 # construct the filter
20 0 my $this = $pkg->SUPER::new(input => [], %arg);
21 0 bless $this, $pkg;
22  
23 # add the fields
24 0 $this->{no_annotation} = $no_annotation;
25  
26 # return the filter
27 0 return $this;
28 }
29  
30 0 ▶sub set_input { # overrides set_input in Text::Filter, adding a type check
Subroutine set_input: not called CC=2 SCAR=17.9
Pod documented
31 0 my ($this,$input,$postread) = @_;
32  
33 0 ▶ ref($input) eq 'ARRAY' or
Branch: 1 branch
BranchTrueFalseTotal
ref $input eq "ARRAY" or die "Invalid input specified,\nText::Annotated::Writer expects an array of Text::Annotated::Line objects,\nstopped" 0 0 0
34 die "Invalid input specified,\n"
35 . "Text::Annotated::Writer expects an array of Text::Annotated::Line objects,\n"
36 . "stopped";
37  
38 0 $this->SUPER::set_input($input,$postread);
39 }
40  
41 0 ▶sub write {
Subroutine write: not called CC=3 SCAR=24.8
Pod undocumented
42 0 my Text::Annotated::Writer $this = shift;
43 0 my $na = $this->{no_annotation};
44 0 ▶ while(defined(my $line = $this->readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $this->readline)) 0 0 0
45 0 ▶ $this->writeline($na
Branch: 1 branch
BranchTrueFalseTotal
$na ? : 0 0 0
46 ? "$line" # this will work both on annotated lines and ordinary strings
47 : $line->stringify_annotated
48 );
49 }
50 }
51  
52 0 ▶sub run { # needed when using the filter in a Text::Filter::Chain
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
53 0 my $this = shift;
54 0 $this->write(@_);
55 }
56  
57 0 ▶sub writer { # constructs and runs the filter
Subroutine writer: not called CC=1 SCAR=6.9
Pod undocumented
58 0 my $proto = shift;
59 0 my $this = $proto->new(@_);
60 0 $this->write;
61 0 return $this;
62 }
63  
64 1 1;
65  
66 __END__
↑ Summary Reader.pm »