Algorithm::Dependency::Source::Invert - Logically invert a source


Algorithm-Dependency documentation Contained in the Algorithm-Dependency distribution.

Index


Code Index:

NAME

Top

Algorithm::Dependency::Source::Invert - Logically invert a source

SYNOPSIS

Top

  my $inverted = Algorithm::Dependency::Source::Invert->new( $source );

DESCRIPTION

Top

This class creates a source from another source, but with all dependencies reversed.

SUPPORT

Top

To file a bug against this module, use the CPAN bug tracking system

http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Algorithm-Dependency

For other comments, contact the author.

AUTHOR

Top

Adam Kennedy <adamk@cpan.org>

SEE ALSO

Top

Algorithm::Dependency::Source, Algorithm::Dependency::Source::HoA

COPYRIGHT

Top


Algorithm-Dependency documentation Contained in the Algorithm-Dependency distribution.
package Algorithm::Dependency::Source::Invert;

use 5.005;
use strict;
use Params::Util '_INSTANCE';
use Algorithm::Dependency::Source::HoA ();

use vars qw{$VERSION @ISA};
BEGIN {
	$VERSION = '1.110';
	@ISA     = 'Algorithm::Dependency::Source::HoA';
}





#####################################################################
# Constructor

sub new {
	my $class  = shift;
	my $source = _INSTANCE(shift, 'Algorithm::Dependency::Source') or return undef;

	# Derive a HoA from the original source
	my @items = $source->items;
	my %hoa   = map { $_->id => [ ] } @items;
	foreach my $item ( @items ) {
		my $id   = $item->id;
		my @deps = $item->depends;
		foreach my $dep ( @deps ) {
			push @{ $hoa{$dep} }, $id;
		}
	}

	# Hand off to the parent class
	$class->SUPER::new( \%hoa );
}

1;