| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # | 
| 2 |  |  |  |  |  |  | # Graph::Writer - perl base class for Graph file format writers | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | package Graph::Writer; | 
| 5 |  |  |  |  |  |  | $Graph::Writer::VERSION = '2.08'; | 
| 6 | 2 |  |  | 2 |  | 1168 | use 5.006; | 
|  | 2 |  |  |  |  | 7 |  | 
| 7 | 2 |  |  | 2 |  | 11 | use strict; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 42 |  | 
| 8 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 11 |  | 
|  | 2 |  |  |  |  | 56 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 2 |  |  | 2 |  | 1695 | use IO::File; | 
|  | 2 |  |  |  |  | 20492 |  | 
|  | 2 |  |  |  |  | 661 |  | 
| 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 |  |  |  |  |  |  | { | 
| 23 | 6 |  |  | 6 | 1 | 1771 | my $class = shift; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 6 | 100 |  |  |  | 23 | die "don't create an instance of $class!\n" if $class eq __PACKAGE__; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 5 |  |  |  |  | 17 | my $self = bless {}, $class; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 5 |  |  |  |  | 27 | $self->_init(@_); | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 5 |  |  |  |  | 13 | 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 |  |  |  | 5 |  |  | { | 
| 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 |  |  |  |  |  |  | { | 
| 59 | 5 |  |  | 5 | 1 | 57 | my $self     = shift; | 
| 60 | 5 |  |  |  |  | 7 | my $graph    = shift; | 
| 61 | 5 |  |  |  |  | 6 | my $filename = shift; | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 5 | 50 |  |  |  | 12 | if (ref $filename) | 
| 65 |  |  |  |  |  |  | { | 
| 66 | 0 |  |  |  |  | 0 | $self->_write_graph($graph, $filename); | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  | else | 
| 69 |  |  |  |  |  |  | { | 
| 70 | 5 |  |  |  |  | 28 | my $FILE = IO::File->new("> $filename"); | 
| 71 | 5 | 50 |  |  |  | 537 | if (not defined $FILE) | 
| 72 |  |  |  |  |  |  | { | 
| 73 | 0 |  |  |  |  | 0 | warn "couldn't write to $filename: $!\n"; | 
| 74 | 0 |  |  |  |  | 0 | return 0; | 
| 75 |  |  |  |  |  |  | } | 
| 76 | 5 |  |  |  |  | 24 | $self->_write_graph($graph, $FILE); | 
| 77 | 5 |  |  |  |  | 22 | $FILE->close(); | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 5 |  |  |  |  | 250 | return 1; | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | 1; | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | __END__ |