perlgraphviz

Perl `gv`module: "No matching function for overloaded 'edge'


The manual page for the Perl gvmodule (graphviz) states:

       New edges

       Add new edge between existing nodes
              edge_handle gv::edge (tail_node_handle, head_node_handle);

Accordingly I wrote a simple test routine:

require 5.026_001;
use warnings;
use strict;

use gv;                 # graphviz
# test
sub test()
{
    my $result = 0;

    if (defined(my $gh = gv::digraph('test'))) {
        if (defined(my $nh = gv::node($gh, 'name'))) {
            if (defined(my $eh = gv::edge($gh, $nh, $nh))) {
                if (gv::write($gh, 'test.out')) {
                    print "success\n";
                } else {
                    print STDERR "$0: failed to write output: $!\n";
                }
            } else {
                print STDERR "$0: failed to create edge\n";
            }
        } else {
            print STDERR "$0: failed to greate node\n";
        }
    } else {
        print STDERR "$0: failed to greate digraph\n";
        $result = 2;
    }
    return $result;
}

my $result = test();

When running it, it fails with

No matching function for overloaded 'edge' at ...

(Seen in SLES15 SP6)


Solution

  • It seems I mixed the two functions

    edge_handle gv::edge (tail_node_handle, head_node_handle);
    

    and

    edge_handle gv::edge (graph_handle, tail_name, head_name);
    

    (The first being a constructor for an edge using node handles, while the second is a constructor using node names, requiring a graph handle.)

    So obviously the first variant can deduce the graph handle from the node handle, thus not needing a graph handle (that was the detail I missed).

    With the fix applied an output graph was created, but the node is named node and labeled \N (instead of name):

    digraph test {
            node [label="\N"];
            name -> name;
    }