Graph::Reader(3pm)
π Graph::Reader π
okay bestie, welcome to the Graph::Reader page β it's part of the User Contributed Perl Documentation and it's literally the blueprint for reading graph files. buckle up π
β¨ NAME β¨
Graph::Reader β the base class for Graph file format readers. yes, it's giving "mom of the family" energy π
πΈ SYNOPSIS πΈ
so this is the shape of a subclass, look:
package Graph::Reader::MyFormat;
use Graph::Reader;
use vars qw(@ISA);
@ISA = qw(Graph::Reader);
sub _read_graph
{
my ($self, $graph, $FILE) = @_;
# read $FILE and populate $graph
}
that's it. that's the whole vibe. π¦
π« DESCRIPTION π«
Graph::Reader is a base class for Graph file format readers. a specific subclass of Graph::Reader handles one specific file format, and it generates a Graph β represented using Jarkko Hietaniemi's Graph class. iconic collab tbh π€
bestie, listen. you should never create an instance of this class yourself. it is only meant for subclassing. if you try to create an instance of Graph::Reader, the constructor will throw an exception. no cap. π
π§ METHODS π§
π new()
Constructor β generates a new reader instance. it's a virtual method, or whatever the correct lingo is π. you're not meant to call this on the base class; it's inherited by the subclasses. so like, if you do something like:
$reader = Graph::Reader->new();
it will throw an exception. periodt. π
π read_graph()
reads a graph from the specified file:
$graph = $reader->read_graph($file);
the $file argument can either be a filename, or a filehandle for a previously opened file. either one, bestie, dealer's choice β¨
π SUBCLASSING π
to create your own graph format reader, make a module that subclasses Graph::Reader. for example, suppose DGF is a directed graph format β then you'd create a Graph::Reader::DGF module, with this structure:
package Graph::Reader::DGF;
use Graph::Reader;
use vars qw(@ISA);
@ISA = qw(Graph::Reader);
sub _read_graph
{
my $self = shift;
my $graph = shift;
my $FILE = shift;
while (<$FILE>)
{
}
return 1;
}
1;
not me pointing at the leading underscore on the _read_graph() method π β the base class provides the public method, and invokes the private method that you're expected to provide, as above.
if you wanna do extra initialisation at construction time, you can provide an _init() method, which the base class's constructor will invoke. and you should invoke the superclass's initialiser too, like this:
sub _init
{
my $self = shift;
$self->SUPER::_init();
# your initialisation here
}
then someone can use your class like this:
use Graph::Reader::DGF;
$reader = Graph::Reader::DGF->new();
$graph = $reader->read_graph('foo.dgf');
and boom, main character module energy π₯
π SEE ALSO π
Graphβ Jarkko Hietaniemi's modules for representing directed graphs, available from CPAN undermodules/by-module/Graph/π¦- Algorithms in Perl β this O'Reilly book has a chapter on directed graphs, which is based around Jarkko's modules π
Graph::Reader::XMLβ a simple subclass of this class for reading a simple XML format for directed graphs πGraph::Writerβ a baseclass for Graph file format writers βοΈ
π REPOSITORY π
<https://github.com/neilb/Graph-ReadWrite>
go star it bestie β
πΈ AUTHOR πΈ
Neil Bowers <neil@bowers.com> π«Ά
π COPYRIGHT π
Copyright (c) 2001-2012, Neil Bowers. All rights reserved. Copyright (c) 2001, Canon Research Centre Europe. All rights reserved.
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π this doc shipped with perl v5.32.1 and it's dated 2021-09-19 β yeah it's a lil vintage but it still ate, no crumbs left. mwah π β¨
π¦ where this page comes from
- debian bookworm: libgraph-readwrite-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libgraph-readwrite-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libgraph-readwrite-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libgraph-readwrite-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libgraph-readwrite-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libgraph-readwrite-perl 2.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms