| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Build::Plugin::Prefer::GoodVersion; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 1310 | use strict; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 57 |  | 
| 4 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 42 |  | 
| 5 | 2 |  |  | 2 |  | 30 | use 5.008004; | 
|  | 2 |  |  |  |  | 7 |  | 
| 6 | 2 |  |  | 2 |  | 366 | use Alien::Build::Plugin; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 7 | 2 |  |  | 2 |  | 11 | use Carp (); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 782 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | # ABSTRACT: Plugin to filter known good versions | 
| 10 |  |  |  |  |  |  | our $VERSION = '2.45'; # VERSION | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | has '+filter' => sub { Carp::croak("The filter property is required for the Prefer::GoodVersion plugin") }; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub init | 
| 16 |  |  |  |  |  |  | { | 
| 17 | 0 |  |  | 0 | 1 |  | my($self, $meta) = @_; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 0 |  |  |  |  |  | $meta->add_requires('configure', __PACKAGE__, '1.44'); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 0 |  |  |  |  |  | my $filter; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 0 | 0 |  |  |  |  | if(ref($self->filter) eq '') | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | { | 
| 25 | 0 |  |  |  |  |  | my $string = $self->filter; | 
| 26 |  |  |  |  |  |  | $filter = sub { | 
| 27 | 0 |  |  | 0 |  |  | my($file) = @_; | 
| 28 | 0 |  |  |  |  |  | $file->{version} eq $string; | 
| 29 | 0 |  |  |  |  |  | }; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  | elsif(ref($self->filter) eq 'ARRAY') | 
| 32 |  |  |  |  |  |  | { | 
| 33 | 0 |  |  |  |  |  | my %filter = map { $_ => 1 } @{ $self->filter }; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | $filter = sub { | 
| 35 | 0 |  |  | 0 |  |  | my($file) = @_; | 
| 36 | 0 |  |  |  |  |  | !! $filter{$file->{version}}; | 
| 37 | 0 |  |  |  |  |  | }; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | elsif(ref($self->filter) eq 'CODE') | 
| 40 |  |  |  |  |  |  | { | 
| 41 | 0 |  |  |  |  |  | my $code = $self->filter; | 
| 42 | 0 |  |  | 0 |  |  | $filter = sub { !! $code->($_[0]) }; | 
|  | 0 |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  | else | 
| 45 |  |  |  |  |  |  | { | 
| 46 | 0 |  |  |  |  |  | Carp::croak("unknown filter type for Prefer::GoodVersion"); | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | $meta->around_hook( | 
| 50 |  |  |  |  |  |  | prefer => sub { | 
| 51 | 0 |  |  | 0 |  |  | my($orig, $build, @therest) = @_; | 
| 52 | 0 |  |  |  |  |  | my $res1 = $orig->($build, @therest); | 
| 53 | 0 | 0 |  |  |  |  | return $res1 unless $res1->{type} eq 'list'; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | return { | 
| 56 |  |  |  |  |  |  | type => 'list', | 
| 57 |  |  |  |  |  |  | list => [ | 
| 58 | 0 |  |  |  |  |  | grep { $filter->($_) } @{ $res1->{list} } | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | ], | 
| 60 |  |  |  |  |  |  | }; | 
| 61 |  |  |  |  |  |  | }, | 
| 62 | 0 |  |  |  |  |  | ); | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | 1; | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | __END__ |