| 1 | # ABSTRACT: Iterates through distribution prerequisites | ||||||||||
| 2 | |||||||||||
| 3 | package Pinto::PrerequisiteWalker; | ||||||||||
| 4 | |||||||||||
| 5 | 58 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 58 | ▶ | use MooseX::StrictConstructor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 58 | ▶ | use MooseX::Types::Moose qw(CodeRef ArrayRef HashRef Bool); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 58 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | #------------------------------------------------------------------------------ | ||||||||||
| 11 | |||||||||||
| 12 | 58 | our $VERSION = '0.14'; # VERSION | |||||||||
| 13 | |||||||||||
| 14 | #------------------------------------------------------------------------------ | ||||||||||
| 15 | |||||||||||
| 16 | 58 | has start => ( | |||||||||
| 17 | is => 'ro', | ||||||||||
| 18 | isa => 'Pinto::Schema::Result::Distribution', | ||||||||||
| 19 | required => 1, | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 58 | has callback => ( | |||||||||
| 23 | is => 'ro', | ||||||||||
| 24 | isa => CodeRef, | ||||||||||
| 25 | required => 1, | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 58 | has filters => ( | |||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | isa => ArrayRef [CodeRef], | ||||||||||
| 31 | predicate => 'has_filters', | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | has queue => ( | ||||||||||
| 35 | isa => ArrayRef ['Pinto::Schema::Result::Prerequisite'], | ||||||||||
| 36 | traits => [qw(Array)], | ||||||||||
| 37 | handles => { enqueue => 'push', dequeue => 'shift' }, | ||||||||||
| 38 | 32 | ▶ | default => sub { return [ $_[0]->apply_filters( $_[0]->start->prerequisites ) ] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 58 | init_arg => undef, | |||||||||
| 40 | lazy => 1, | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | has seen => ( | ||||||||||
| 44 | is => 'ro', | ||||||||||
| 45 | isa => HashRef, | ||||||||||
| 46 | 0 | ▶ | default => sub { return { $_[0]->start->path => 1 } }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 47 | 58 | init_arg => undef, | |||||||||
| 48 | lazy => 1, | ||||||||||
| 49 | ); | ||||||||||
| 50 | |||||||||||
| 51 | #----------------------------------------------------------------------------- | ||||||||||
| 52 | |||||||||||
| 53 | 34 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=4 SCAR=17.3
Pod
undocumented
| |||||||||||
| 54 | 34 | my ($self) = @_; | |||||||||
| 55 | |||||||||||
| 56 | 34 | ▶ | my $prereq = $self->dequeue or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 2 | my $dist = $self->callback->($prereq); | |||||||||
| 58 | |||||||||||
| 59 | 2 | ▶ | if ( defined $dist ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | my $path = $dist->path; | |||||||||
| 61 | 0 | my @prereqs = $self->apply_filters( $dist->prerequisites ); | |||||||||
| 62 | 0 | ▶ | $self->enqueue(@prereqs) unless $self->seen->{$path}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | $self->seen->{$path} = 1; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 2 | return $prereq; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | #------------------------------------------------------------------------------ | ||||||||||
| 70 | |||||||||||
| 71 | 32 | ▶ | sub apply_filters { | ||||||||
|
Subroutine
apply_filters: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 72 | 32 | my ( $self, @prereqs ) = @_; | |||||||||
| 73 | |||||||||||
| 74 | 32 | ▶ | return @prereqs if not $self->has_filters; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | |||||||||||
| 76 | 32 | for my $filter ( @{ $self->filters } ) { | |||||||||
| 77 | 64 | @prereqs = grep { !$filter->($_) } @prereqs; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 32 | return @prereqs; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | #------------------------------------------------------------------------------ | ||||||||||
| 84 | |||||||||||
| 85 | 58 | __PACKAGE__->meta->make_immutable; | |||||||||
| 86 | |||||||||||
| 87 | #------------------------------------------------------------------------------- | ||||||||||
| 88 | 58 | 1; | |||||||||
| 89 | |||||||||||
| 90 | __END__ | ||||||||||