package Graph::igraph; use strict; use warnings; use 5.012; use Carp; use autodie; use utf8; use Alien::igraph; use FFI::Platypus; use FFI::Platypus::API; my $ffi = FFI::Platypus->new; $ffi->lib(Alien::igraph->dynamic_libs); $ffi->type('int' => 'igraph_integer_t'); $ffi->type('int' => 'igraph_bool_t'); $ffi->type('double' => 'igraph_real_t'); $ffi->type('opaque' => 'igraph_t'); $ffi->load_custom_type('::StringPointer' => 'string_pointer'); $ffi->attach([igraph_empty => 'new'] => [qw/igraph_t igraph_integer_t igraph_bool_t/] => 'int', sub { my ($xsub, $class, %options) = @_; my $graph; if ($options{undirected}) { say 'undirected -- ' . $xsub->(\$graph, 0, 0); } else { say 'directed -- ' . $xsub->(\$graph, 0, 1); } say 'weird: this line says "Use of uninitialized value in say"'; return bless \$graph, $class; }); $ffi->attach([igraph_destroy => 'DESTROY'] => [qw/igraph_t/] => 'int'); $ffi->attach(igraph_vcount => ['igraph_t'] => 'igraph_integer_t'); $ffi->attach(igraph_add_vertices => [qw/igraph_t igraph_integer_t/] => 'int'); $ffi->attach(igraph_version => [qw/string_pointer int* int* int*/] => 'int'); sub version { my ($version, $major, $minor, $patch); igraph_version(\$version, \$major, \$minor, \$patch); return ($version, $major, $minor, $patch); } sub add_vertex { my $self = shift; igraph_add_vertices($self, 1); } sub count_vertices { my $self = shift; igraph_vcount($self); } 1;