Algorithm-Dependency-Objects

 view release on metacpan or  search on metacpan

lib/Algorithm/Dependency/Objects.pm  view on Meta::CPAN

#!/usr/bin/perl

package Algorithm::Dependency::Objects;

use strict;
use warnings;

our $VERSION = '0.04';

use Scalar::Util qw/blessed/;
use Carp qw/croak/;

use Set::Object;

sub _to_set {
	my ( $class, $objects ) = @_;

	if ( ref $objects ) {
		$objects = Set::Object->new(@$objects) if not blessed $objects and ref $objects eq 'ARRAY';

		if ( blessed $objects and $objects->isa("Set::Object") ) {
			return $objects;
		}
	}

	return;
}

sub new {
	my ($class, %params) = @_;

lib/Algorithm/Dependency/Objects.pm  view on Meta::CPAN

	my $selected = exists($params{selected})
		? $class->_to_set($params{selected})
		: Set::Object->new()
			or croak "If provided, the 'selected' parameter must be an array reference or a Set::Object";
	
	# all the contents of the Set::Object must have depends methods
	$class->assert_can_get_deps($objects);

	$objects = $class->verify_input_set($objects);

	return bless {
		objects  => $objects,
		selected => $selected,
	}, $class;
}

sub objects  { (shift)->{objects}  }
sub selected { (shift)->{selected} }

sub get_deps {
	my ( $self, $obj ) = @_;

t/01_basics.t  view on Meta::CPAN

	use Scalar::Util qw/refaddr/;

	use overload '""' => 'id', fallback => 1;

	my $id = 'A';
	my %id;
	
	sub id { $id{refaddr $_[0]} }
	sub new {
		my $pkg = shift;
		my $self = bless [ @_ ], $pkg;
		$id{refaddr $self} = $id++;
		$self;
	}
	sub depends {
		@{ $_[0] }
	}
}

use Set::Object;



( run in 1.502 second using v1.01-cache-2.11-cpan-de7293f3b23 )