Writer.pm

filter: Statementstmt 93.3% 28 / 30 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 93.3% 42 / 45 CC 4 SCAR 6.0
CC
4
Cov
92%
write_graph
3.1
new
2.0
BEGIN
1.0
CRAP 1.8
« ReadWrite.pm ↑ Summary Reader/XML.pm »
1 #
2 # Graph::Writer - perl base class for Graph file format writers
3 #
4 package Graph::Writer;
5 3 $Graph::Writer::VERSION = '2.10';
6 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 #=======================================================================
13 #
14 # new () - constructor
15 #
16 # Create an instance of a Graph writer. This will not be invoked
17 # directly on this class, but will be inherited by writers for
18 # specific formats.
19 #
20 #=======================================================================
21 sub new
22 11 ▶{
Subroutine new: called CC=2 SCAR=6.9
Pod documented
23 11 my $class = shift;
24  
25 11 ▶ die "don't create an instance of $class!\n" if $class eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ 1 10 11
26  
27 10 my $self = bless {}, $class;
28  
29 10 $self->_init(@_);
30  
31 10 return $self;
32 }
33  
34 #=======================================================================
35 #
36 # _init() - initialise instance
37 #
38 # This is for any instance-specific initialisation. The idea is that
39 # a sub-class will define an _init() method if it needs one.
40 # For future compatibility the class-specific method should invoke
41 # this.
42 #
43 #=======================================================================
44 sub _init
45 10 ▶{
Subroutine _init: called CC=1 SCAR=0.0
46 }
47  
48  
49 #=======================================================================
50 #
51 # write_graph() - write the specified graph to the specified file (handle)
52 #
53 # This is the public method that will be invoked to write a graph.
54 # The file can be specified either as a filename, or a filehandle.
55 #
56 #=======================================================================
57 sub write_graph
58 10 ▶{
Subroutine write_graph: called CC=3 SCAR=11.2
Pod documented
59 10 my $self = shift;
60 10 my $graph = shift;
61 10 my $filename = shift;
62  
63  
64 10 ▶ if (ref $filename)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $filename) { } 5 5 10
65 {
66 5 $self->_write_graph($graph, $filename);
67 }
68 else
69 {
70 5 my $FILE = IO::File->new("> $filename");
71 5 ▶ if (not defined $FILE)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $FILE) 0 5 5
72 {
73 0 warn "couldn't write to $filename: $!\n";
74 0 return 0;
75 }
76 5 $self->_write_graph($graph, $FILE);
77 5 $FILE->close();
78 }
79  
80 10 return 1;
81 }
82  
83 3 1;
84  
85 __END__
« ReadWrite.pm ↑ Summary Reader/XML.pm »