Algorithm-DependencySolver
view release on metacpan or search on metacpan
lib/Algorithm/DependencySolver/Solver.pm view on Meta::CPAN
id => 3,
depends => [qw(y)],
affects => [qw(z)],
prerequisites => [],
),
);
my $solver =
Algorithm::DependencySolver::Solver->new(nodes => \@operations);
$solver->to_png("pretty-graph.png");
my $traversal = Algorithm::DependencySolver::Traversal->new(
Solver => $solver,
visit => sub {
my $operation = shift;
print "Visited operation: ", $operation->id, "\n";
},
);
lib/Algorithm/DependencySolver/Solver.pm view on Meta::CPAN
builder => 'build_affects_index',
lazy => 1,
init_arg => undef,
);
=head2 get_Graph
Returns the dependency graph as a L<Graph> object. Note that only
operations are included in the graph, not resources. This is of most
use to the L<Algorithm::DependencySolver::Traversal> module, and the
C<to_dot> and C<to_png> methods.
=cut
has 'Graph' => (
is => 'ro',
builder => 'build_Graph',
lazy => 1,
init_arg => undef,
);
lib/Algorithm/DependencySolver/Solver.pm view on Meta::CPAN
push @{$index{$resource}}, $node;
}
}
return \%index;
}
method to_s() {
return $self->get_GraphEasy->as_ascii();
}
=head2 to_png
$solver->to_png($file)
Outputs a dependency graph (showing only operations) to the given file
in PNG format
=cut
method to_png($file) {
die "Only sane file names, please (you gave: $file)" unless
$file =~ m/^[a-z0-9_\-\.\/]+$/i;
open my $dot, "|dot -Tpng -o'$file'" or die ("Cannot open pipe to dot (-o $file): $!");
print $dot $self->get_GraphEasy->as_graphviz;
}
=head2 to_dot
$solver->to_dot($file)
Outputs a dependency graph (showing only operations) to the given file
in Graphviz's dot format
t/02-solver.t view on Meta::CPAN
use File::Type;
use File::Spec::Functions;
use File::Which;
use Algorithm::DependencySolver::Operation;
use Algorithm::DependencySolver::Solver;
# This tests checks that a Solver object can be created
# and that the methods on the solver work as expected.
# The testable methods on the Solver object are to_png and to_dot. The other
# more graph-y methods will be tested by the Traversal test.
my @operations = (
Algorithm::DependencySolver::Operation->new(
id => 'First',
depends => [ ],
affects => [ 'a' ],
prerequisites => [ ],
),
Algorithm::DependencySolver::Operation->new(
t/02-solver.t view on Meta::CPAN
my $solver = Algorithm::DependencySolver::Solver->new(
nodes => \@operations
);
ok $solver, 'created Solver object with 3 Operations';
my $ft = File::Type->new();
my $test_tempdir = tempdir();
SKIP: {
## Testing that to_png() works correctly
# requires the "dot" binary from graphviz to exist
skip("'dot' binary not found", 2) unless (which('dot'));
my $temp_png = catfile($test_tempdir, 'temp.png');
$solver->to_png($temp_png);
ok -f $temp_png, "created temporary png file ($temp_png)";
is $ft->checktype_filename($temp_png), 'image/x-png', "File::Type thinks it is a PNG file ($temp_png)";
}
SKIP: {
## Testing that to_dot() works correctly
# requires the "dot" binary from graphviz to exist
skip("'dot' binary not found", 2) unless (which('dot'));
my $temp_dot = catfile($test_tempdir, 'temp.dot');
$solver->to_dot($temp_dot);
( run in 0.695 second using v1.01-cache-2.11-cpan-df04353d9ac )