File Coverage

blib/lib/Graph/Reader.pm
Criterion Covered Total %
statement 15 32 46.8
branch 1 6 16.6
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 23 47 48.9


line stmt bran cond sub pod time code
1             #
2             # Graph::Reader - perl base class for Graph file format readers
3             #
4             package Graph::Reader;
5              
6 2     2   652 use strict;
  2         3  
  2         69  
7 2     2   8 use warnings;
  2         4  
  2         79  
8              
9             our $VERSION = '2.07';
10              
11 2     2   518 use IO::File;
  2         7753  
  2         201  
12 2     2   725 use Graph;
  2         87024  
  2         376  
13              
14             #=======================================================================
15             #
16             # new () - constructor
17             #
18             #=======================================================================
19             sub new
20             {
21 1     1 1 34 my $class = shift;
22 1         3 my %args = @_;
23              
24 1 50       9 die "don't create an instance of $class!\n" if $class eq __PACKAGE__;
25              
26 0           my $self = bless {}, $class;
27              
28 0           $self->_init(\%args);
29              
30 0           return $self;
31             }
32              
33             #=======================================================================
34             #
35             # _init() - initialise instance
36             #
37             # This is for any instance-specific initialisation. The idea is that
38             # a sub-class will define an _init() method if it needs one.
39             # For future compatibility the class-specific method should invoke
40             # this.
41             #
42             #=======================================================================
43             sub _init
44 0     0     {
45             }
46              
47             #=======================================================================
48             #
49             # read_graph() - create a Graph and read the given file into it
50             #
51             # This is the public method that will be invoked to read a graph.
52             # The file can be specified either as a filename, or a filehandle.
53             #
54             #=======================================================================
55             sub read_graph
56             {
57 0     0 1   my $self = shift;
58 0           my $filename = shift;
59              
60 0           my $graph = Graph->new();
61 0           my $FILE;
62              
63              
64 0 0         if (ref $filename)
65             {
66 0           $self->_read_graph($graph, $filename);
67             }
68             else
69             {
70 0           $FILE = IO::File->new("< $filename");
71 0 0         if (not defined $FILE)
72             {
73 0           warn "couldn't read from $filename: $!\n";
74 0           return 0;
75             }
76 0           $self->_read_graph($graph, $FILE);
77 0           $FILE->close();
78             }
79              
80 0           return $graph;
81             }
82              
83             1;
84              
85             __END__