Graph::Writer(3pm)
π Graph::Writer β the base class era π
okay so bestie, we're looking at Graph::Writer, a User Contributed Perl Documentation page, and it's literally the blueprint page for making Graph file format writers. it's giving founding mother energy fr fr π
β¨ NAME β¨
Graph::Writer β bestie it's the base class for Graph file format writers. that's the whole vibe. π
πΈ SYNOPSIS πΈ
here's the little starter pack, copy it verbatim okay:
package Graph::Writer::MyFormat;
use Graph::Writer;
use vars qw(@ISA);
@ISA = qw(Graph::Writer);
sub _write_graph
{
my ($self, $graph, $FILE) = @_;
# write $graph to $FILE
}
π¦ DESCRIPTION π¦
so Graph::Writer is the base class for Graph file format writers. a specific subclass of Graph::Writer handles one specific file format, and generates a Graph, represented using Jarkko Hietaniemi's Graph class. iconic honestly.
NOT me creating an instance of this class myself π bestie you should never do that, it is only meant for subclassing. if you try to create an instance of Graph::Writer, the constructor will throw an exception. periodt.
π METHODS π
new()
Constructor β generate a new writer instance. this is 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. like, if you do something like:
$writer = Graph::Writer->new();
it will throw an exception. no cap, it's not gonna work bestie. π
write_graph()
read a graph from the specified file:
$graph = $writer->write_graph($file);
the $file argument can either be a filename, or a filehandle for a previously opened file. either one, she's flexible like that. π«Ά
π§ SUBCLASSING π§
to create your own graph format writer, create a module which subclasses Graph::Writer. for example, suppose DGF is a directed graph format β create a Graph::Writer::DGF module, with the following structure:
package Graph::Writer::DGF;
use Graph::Writer;
use vars qw(@ISA);
@ISA = qw(Graph::Writer);
sub _write_graph
{
my $self = shift;
my $graph = shift;
my $FILE = shift;
while (<$FILE>)
{
}
return 1;
}
1;
note the leading underscore on the _write_graph() method. the base class provides the public method, and invokes the private method which you're expected to provide, as above. that's the deal, that's the assignment. π
if you want to perform additional initialisation at construction time, you can provide an _init() method, which will be invoked by the base class's constructor. you should invoke the superclass's initialiser as well, as follows:
sub _init
{
my $self = shift;
$self->SUPER::_init();
# your initialisation here
}
someone can then use your class as follows:
use Graph::Writer::DGF;
$writer = Graph::Writer::DGF->new();
$writer->write_graph($graph, 'foo.dgf');
slay. your little module is out there living its main character life β¨
π SEE ALSO π
Graphβ Jarkko Hietaniemi's modules for representing directed graphs, available from CPAN undermodules/by-module/Graph/Algorithms in Perlβ the O'Reilly book has a chapter on directed graphs, which is based around Jarkko's modules.Graph::Writer::Dotβ a simple subclass of this class for writing graphs in the file format used bydot, which is part of the graphviz package from AT&T.Graph::Writer::VCGβ a simple subclass of this class for writing graphs in the file format used byVCG, a tool for visualising directed graphs, initially developed for visualising compiler graphs.Graph::Writer::XMLβ a simple subclass of this class for writing graphs as XML, using a simple graph markup.Graph::Readerβ a baseclass for Graph file format readers.
π REPOSITORY π
<https://github.com/neilb/Graph-ReadWrite>
go look, it's right there 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.
okay and that's the whole page!! this was documented by perl v5.32.1 and dated 2021-09-19, so if you're reading this in the future, the vibes are preserved, don't worry π bye bestie, go subclass something iconic πΈπ
π¦ 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