Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out G::D::Dependencies from G::D::Node
- Loading branch information
Showing
3 changed files
with
54 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package Graph::Dependency::Dependencies; | ||
use Any::Moose; | ||
use Any::Moose 'Util::TypeConstraints'; | ||
|
||
coerce 'Graph::Dependency::Dependencies', from 'HashRef[Str]', via { Graph::Dependency::Dependencies->new(dependencies => $_) }; | ||
|
||
has dependencies => ( | ||
isa => 'HashRef[Str]', | ||
default => sub { {} }, | ||
init_arg => 'dependencies', | ||
traits => ['Hash'], | ||
handles => { | ||
all => 'keys', | ||
_kv => 'kv', | ||
has => 'count', | ||
get => 'get', | ||
set => 'set', | ||
delete => 'delete', | ||
_flat => 'elements', | ||
_types => 'values', | ||
}, | ||
); | ||
|
||
sub types { | ||
my $self = shift; | ||
return List::MoreUtils::uniq($self->_types); | ||
} | ||
|
||
sub for_type { | ||
my ($self, $wanted_type) = @_; | ||
my @ret; | ||
for my $pair ($self->_kv) { | ||
my ($name, $type) = @{$pair}; | ||
push @ret, $name if $type eq $wanted_type; | ||
} | ||
return @ret; | ||
} | ||
|
||
sub to_hashref { | ||
my $self = shift; | ||
return { $self->_flat_elements }; | ||
} | ||
|
||
1; | ||
|
||
__END__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters