Graph-Reader-OID
view release on metacpan or search on metacpan
package Graph::Reader::OID;
use base qw(Graph::Reader);
use strict;
use warnings;
use Readonly;
# Constants.
Readonly::Scalar our $DOT => q{.};
Readonly::Scalar our $EMPTY_STR => q{};
# Version.
our $VERSION = 0.05;
# Read graph subroutine.
sub _read_graph {
my ($self, $graph, $fh) = @_;
while (my $line = <$fh>) {
chomp $line;
# End of vertexes section.
if ($line =~ m/^#/ms) {
next;
}
# Process OID.
my ($line_oid, $line_label) = split m/\s+/ms, $line, 2;
my @oid = split m/\./ms, $line_oid;
my $last_oid;
my $act_oid = $EMPTY_STR;
foreach my $oid (@oid) {
if ($act_oid ne $EMPTY_STR) {
$act_oid .= $DOT;
}
$act_oid .= $oid;
$graph->add_vertex($act_oid);
if ($act_oid eq $line_oid) {
if (! $line_label) {
$line_label = $line_oid;
}
$graph->set_vertex_attribute($act_oid, 'label',
$line_label);
}
if (defined $last_oid) {
$graph->add_edge($last_oid, $act_oid);
}
$last_oid = $act_oid;
}
}
return;
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
Graph::Reader::OID - Perl class for reading a graph from OID format.
=head1 SYNOPSIS
use Graph::Reader::OID;
my $obj = Graph::Reader::OID->new;
my $graph = $obj->read_graph($oid_file);
=head1 METHODS
=over 8
=item C<new()>
Constructor.
This doesn't take any arguments.
Returns Graph::Reader::OID object.
=item C<read_graph($tgf_file)>
Read a graph from the specified file.
The argument can either be a filename, or a filehandle for a previously opened file.
Returns Graph object.
=back
( run in 1.147 second using v1.01-cache-2.11-cpan-71847e10f99 )