The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


VCG - Interface to the VCG graphing tool


  use VCG;
  my $vcg = VCG->new(outfile=>'resulta.vcg');
  $vcg->add_node(title => 'aaa');
  $vcg->add_node(title => 'bbb', label='b');
  $vcg->add_node(title => 'ccc', color=>'yellow');

  $vcg->add_edge(source => 'aaa', target=>'bbb');



  my $data = $vcg->as_ppm();
  open (OUTFILE, 'outfile.ppm') or die "error $!\n";
  print OUTFILE $data;
  close OUTFILE;


This module provides an interface to to the vcg graphing tool. It supports a limited selection of options and file formats. The vcg graphing tool homepage is currently but is being actively developed elsewhere.

This module is based on Leon Brocard's GraphViz module, it tries to provide a similar interface to offer some sense of consistency.

VCG is now in active development and although Graph::Writer::VCG already exists, this module provides a similar interface to graphviz and will be more closely tied into vcg as it becomes more actively developed - see James Micheal DuPont's announcement at



new objects are created using the constructor method 'new'.

This method accepts name attributes in the form :

my $vcg = VCG->new(outfile=>'foo.pbm')

my $vcg = VCG->new(title=>'Dia Dependancies Diagram',debug=>1);

my $vcg = VCG->new();

my %config = ( xmax => 700, ymax=>700, program=>'xvcg', x=>30, y=>30 ); my $vcg = VCG->new(%config);

my $vcg = VCG->new( outfile=>'', landscape=>1, paper=>'tabloid', spline=>1 );


add_edge allows you to add edges to your vcg object (edges are the lines or relationships between nodes).

In a Finite State Diagram, edges would represent transitions between states.

This method accepts the source, target and colour of the edge :

$vcg->add_edge( source=>'from_node', target=>'to_node');

$vcg->add_edge( source=>'aaa', target=>'bbb', color=>'grey');


add_node allows you to add nodes to your vcg object (nodes are the things connected, while edges are the connections).

In a Finite State Diagram, nodes would be the individual states.

This method accepts the label, title and background colour of the node :

$vcg->add_node( title=>'aaa' );

$vcg->add_node( label=>'aaa' );

$vcg->add_node( label=>'aaa', title=>'A', color=>'yellow' );


You can get the version and copyright message as a string using the vcg object (requires vcg be installed)

my $version = $vcg->get_vcg_version() or die "couldn't get version : $vcg->error() \n";

as_ps, as_pbm, as_ppm, as_vcg, as_plainvcg

The VCG object allows you to access the output of the vcg tool directly, suitable for using with graphic libraries - although some libraries or older versions may not be able to cope with these formats.

You can access the output in any of postscript, pbm, ppm, vcg (annotated) and vcg (plain) :

my $image_as_ppm = $vcg->as_ppm(); # string of image as formatted as ppm

my $vcg_with_coords = $vcg->as_vcg(); # handy for building a pixmap or something or converting to dia xml for example

output_as_ps, output_as_pbm, output_as_ppm

The VCG object allows you to output straight to a file through the vcg tool in any of postscript, pbm and ppm. This functionality requires that the vcg tool be installed.

$vcg->output_as_ps(''); # now open the file in the gimp or import into LaTeX and you can get this free Mad Scientist (TM) white coat and bunsen burner.

output_as_vcg, output_as_plainvcg

The VCG object also allows you to output straight to file in annotated vcg with coordinates, or plain vcg syntax. The plain syntax does not require the vcg tool to be installed.

$vcg->output_as_plainvcg('compiler_graph.vcg'); # just in case you want to generate a diagram but don't have vcg installed.

$vcg->output_as_vcg('compiler_graph_with_coords.vcg'); # lovely jubbly


  GraphViz :

  GraphViz perl module

  Graph::Writer::VCG perl module

  vcg/xvcg : man pages


Aaron Trevena <>


Copyright (C) 2003, Aaron Trevena, Leon Brocard

This module is free software; you can redistribute it or modify it under the same terms as Perl itself.