| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Build::Plugin; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 60 |  |  | 319 |  | 259917 | use strict; | 
|  | 60 |  |  |  |  | 119 |  | 
|  | 60 |  |  |  |  | 1675 |  | 
| 4 | 60 |  |  | 60 |  | 291 | use warnings; | 
|  | 60 |  |  |  |  | 107 |  | 
|  | 60 |  |  |  |  | 1223 |  | 
| 5 | 60 |  |  | 60 |  | 878 | use 5.008004; | 
|  | 60 |  |  |  |  | 226 |  | 
| 6 | 60 |  |  | 60 |  | 34698 | use Data::Dumper (); | 
|  | 60 |  |  |  |  | 358401 |  | 
|  | 60 |  |  |  |  | 1638 |  | 
| 7 | 60 |  |  | 60 |  | 493 | use Carp (); | 
|  | 60 |  |  |  |  | 121 |  | 
|  | 60 |  |  |  |  | 869 |  | 
| 8 | 60 |  |  | 60 |  | 31278 | use Digest::SHA (); | 
|  | 60 |  |  |  |  | 169504 |  | 
|  | 60 |  |  |  |  | 19451 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | our @CARP_NOT = qw( alienfile Alien::Build Alien::Build::Meta ); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | # ABSTRACT: Plugin base class for Alien::Build | 
| 13 |  |  |  |  |  |  | our $VERSION = '2.45'; # VERSION | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub new | 
| 17 |  |  |  |  |  |  | { | 
| 18 | 2947 |  |  | 2947 | 1 | 257929 | my $class = shift; | 
| 19 | 2947 | 100 |  |  |  | 8362 | my %args = @_ == 1 ? ($class->meta->default => $_[0]) : @_; | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 2947 |  |  |  |  | 14071 | my $instance_id = Digest::SHA::sha1_hex(Data::Dumper->new([$class, \%args])->Sortkeys(1)->Dump); | 
| 22 | 2947 |  |  |  |  | 172163 | my $self = bless { instance_id => $instance_id }, $class; | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 2947 |  |  |  |  | 10201 | my $prop = $self->meta->prop; | 
| 25 | 2947 |  |  |  |  | 8339 | foreach my $name (keys %$prop) | 
| 26 |  |  |  |  |  |  | { | 
| 27 |  |  |  |  |  |  | $self->{$name} = defined $args{$name} | 
| 28 |  |  |  |  |  |  | ? delete $args{$name} | 
| 29 |  |  |  |  |  |  | : ref($prop->{$name}) eq 'CODE' | 
| 30 |  |  |  |  |  |  | ? $prop->{$name}->() | 
| 31 | 1043 | 100 |  |  |  | 4433 | : $prop->{$name}; | 
|  |  | 100 |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 2947 |  |  |  |  | 5357 | foreach my $name (keys %args) | 
| 35 |  |  |  |  |  |  | { | 
| 36 | 0 |  |  |  |  | 0 | Carp::carp "$class has no $name property"; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 2947 |  |  |  |  | 7526 | $self; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 62 |  |  | 62 | 1 | 242 | sub instance_id { shift->{instance_id} } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub init | 
| 47 |  |  |  |  |  |  | { | 
| 48 | 0 |  |  | 0 | 1 | 0 | my($self) = @_; | 
| 49 | 0 |  |  |  |  | 0 | $self; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub import | 
| 53 |  |  |  |  |  |  | { | 
| 54 | 614 |  |  | 614 |  | 4207 | my($class) = @_; | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 614 | 100 |  |  |  | 17653 | return if $class ne __PACKAGE__; | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 531 |  |  |  |  | 1243 | my $caller = caller; | 
| 59 | 60 |  |  | 60 |  | 568 | { no strict 'refs'; @{ "${caller}::ISA" } = __PACKAGE__ } | 
|  | 60 |  |  |  |  | 146 |  | 
|  | 60 |  |  |  |  | 7205 |  | 
|  | 531 |  |  |  |  | 904 |  | 
|  | 531 |  |  |  |  | 803 |  | 
|  | 531 |  |  |  |  | 10832 |  | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 531 |  |  |  |  | 5359 | my $meta = $caller->meta; | 
| 62 |  |  |  |  |  |  | my $has = sub { | 
| 63 | 448 |  |  | 448 |  | 10514 | my($name, $default) = @_; | 
| 64 | 448 |  |  |  |  | 1024 | $meta->add_property($name, $default); | 
| 65 | 531 |  |  |  |  | 3111 | }; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 60 |  |  | 60 |  | 440 | { no strict 'refs'; *{ "${caller}::has" } = $has } | 
|  | 60 |  |  |  |  | 218 |  | 
|  | 60 |  |  |  |  | 27709 |  | 
|  | 531 |  |  |  |  | 1039 |  | 
|  | 531 |  |  |  |  | 721 |  | 
|  | 531 |  |  |  |  | 58822 |  | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | sub subplugin | 
| 72 |  |  |  |  |  |  | { | 
| 73 | 1 |  |  | 1 | 1 | 33 | my(undef, $name, %args) = @_; | 
| 74 | 1 |  |  |  |  | 211 | Carp::carp("subplugin method is deprecated"); | 
| 75 | 1 |  |  |  |  | 71 | my $class = "Alien::Build::Plugin::$name"; | 
| 76 | 1 |  |  |  |  | 4 | my $pm = "$class.pm"; | 
| 77 | 1 |  |  |  |  | 6 | $pm =~ s/::/\//g; | 
| 78 | 1 | 50 |  |  |  | 3 | require $pm unless eval { $class->can('new') }; | 
|  | 1 |  |  |  |  | 15 |  | 
| 79 | 1 |  |  |  |  | 5 | delete $args{$_} for grep { ! defined $args{$_} } keys %args; | 
|  | 2 |  |  |  |  | 8 |  | 
| 80 | 1 |  |  |  |  | 4 | $class->new(%args); | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | my %meta; | 
| 85 |  |  |  |  |  |  | sub meta | 
| 86 |  |  |  |  |  |  | { | 
| 87 | 3514 |  |  | 3514 | 1 | 6778 | my($class) = @_; | 
| 88 | 3514 | 100 |  |  |  | 9251 | $class = ref $class if ref $class; | 
| 89 | 3514 |  | 66 |  |  | 14120 | $meta{$class} ||= Alien::Build::PluginMeta->new( class => $class ); | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | package Alien::Build::PluginMeta; | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | sub new | 
| 95 |  |  |  |  |  |  | { | 
| 96 | 532 |  |  | 532 |  | 1751 | my($class, %args) = @_; | 
| 97 | 532 |  |  |  |  | 6063 | my $self = bless { | 
| 98 |  |  |  |  |  |  | prop => {}, | 
| 99 |  |  |  |  |  |  | %args, | 
| 100 |  |  |  |  |  |  | }, $class; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | sub default | 
| 104 |  |  |  |  |  |  | { | 
| 105 | 35 |  |  | 35 |  | 81 | my($self) = @_; | 
| 106 | 35 | 50 |  |  |  | 201 | $self->{default} || do { | 
| 107 | 0 |  |  |  |  | 0 | Carp::croak "No default for @{[ $self->{class} ]}"; | 
|  | 0 |  |  |  |  | 0 |  | 
| 108 |  |  |  |  |  |  | }; | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | sub add_property | 
| 112 |  |  |  |  |  |  | { | 
| 113 | 448 |  |  | 448 |  | 824 | my($self, $name, $default) = @_; | 
| 114 | 448 |  |  |  |  | 1240 | my $single = $name =~ s{^(\+)}{}; | 
| 115 | 448 | 100 |  |  |  | 1194 | $self->{default} = $name if $single; | 
| 116 | 448 |  |  |  |  | 909 | $self->{prop}->{$name} = $default; | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | my $accessor = sub { | 
| 119 | 1557 |  |  | 1557 |  | 5201 | my($self, $new) = @_; | 
| 120 | 1557 | 100 |  |  |  | 2884 | $self->{$name} = $new if defined $new; | 
| 121 | 1557 |  |  |  |  | 6186 | $self->{$name}; | 
| 122 | 448 |  |  |  |  | 1499 | }; | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | # add the accessor | 
| 125 | 60 |  |  | 60 |  | 499 | { no strict 'refs'; *{ $self->{class} . '::' . $name} = $accessor } | 
|  | 60 |  |  |  |  | 154 |  | 
|  | 60 |  |  |  |  | 6260 |  | 
|  | 448 |  |  |  |  | 735 |  | 
|  | 448 |  |  |  |  | 567 |  | 
|  | 448 |  |  |  |  | 2277 |  | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 448 |  |  |  |  | 1079 | $self; | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | sub prop | 
| 131 |  |  |  |  |  |  | { | 
| 132 | 2947 |  |  | 2947 |  | 6393 | shift->{prop}; | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | 1; | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | __END__ |