| 1 | package Alien::Build::Plugin; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 68 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 68 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 68 | ▶ | use 5.008004; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 68 | ▶ | use Data::Dumper (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 68 | ▶ | use Carp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 68 | ▶ | use Digest::SHA (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 68 | our @CARP_NOT = qw( alienfile Alien::Build Alien::Build::Meta ); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # ABSTRACT: Plugin base class for Alien::Build | ||||||||||||||||||||
| 13 | 68 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub new | ||||||||||||||||||||
| 17 | 3602 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 18 | 3602 | my $class = shift; | |||||||||||||||||||
| 19 | 3602 | ▶ | my %args = @_ == 1 ? ($class->meta->default => $_[0]) : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 3602 | my $instance_id = Digest::SHA::sha1_hex(Data::Dumper->new([$class, \%args])->Sortkeys(1)->Dump); | |||||||||||||||||||
| 22 | 3602 | my $self = bless { instance_id => $instance_id }, $class; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 3602 | my $prop = $self->meta->prop; | |||||||||||||||||||
| 25 | 3602 | 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 | 1578 | ▶ | : $prop->{$name}; | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 3600 | foreach my $name (keys %args) | |||||||||||||||||||
| 35 | { | ||||||||||||||||||||
| 36 | 0 | Carp::carp "$class has no $name property"; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 3600 | $self; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 62 | ▶ | sub instance_id { shift->{instance_id} } | ||||||||||||||||||
|
Subroutine
instance_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | sub init | ||||||||||||||||||||
| 47 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 48 | 0 | my($self) = @_; | |||||||||||||||||||
| 49 | 0 | $self; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub import | ||||||||||||||||||||
| 53 | 754 | ▶ | { | ||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 54 | 754 | my($class) = @_; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 754 | ▶ | return if $class ne __PACKAGE__; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 663 | my $caller = caller; | |||||||||||||||||||
| 59 | 68 | ▶ | { no strict 'refs'; @{ "${caller}::ISA" } = __PACKAGE__ } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 663 | my $meta = $caller->meta; | |||||||||||||||||||
| 62 | 607 | ▶ | my $has = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 63 | 607 | my($name, $default) = @_; | |||||||||||||||||||
| 64 | 607 | $meta->add_property($name, $default); | |||||||||||||||||||
| 65 | 663 | }; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 68 | ▶ | { no strict 'refs'; *{ "${caller}::has" } = $has } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 68 | my %meta; | |||||||||||||||||||
| 72 | sub meta | ||||||||||||||||||||
| 73 | 4330 | ▶ | { | ||||||||||||||||||
|
Subroutine
meta: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 74 | 4330 | my($class) = @_; | |||||||||||||||||||
| 75 | 4330 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 4330 | ▶ | $meta{$class} ||= Alien::Build::PluginMeta->new( class => $class ); | ||||||||||||||||||
|
Condition66%2/3
$meta{$class} ||= "Alien::Build::PluginMeta"->new("class", $class)
MC/DC0%0/2
$meta{$class} ||= "Alien::Build::PluginMeta"->new("class", $class)
$meta{$class}
"Alien::Build::PluginMeta"->new("class", $class)
Truth table66%2/3
A ||= B
A= $meta{$class}B= "Alien::Build::PluginMeta"->new("class", $class)
| |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | package Alien::Build::PluginMeta; | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | sub new | ||||||||||||||||||||
| 82 | 664 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 83 | 664 | my($class, %args) = @_; | |||||||||||||||||||
| 84 | 664 | my $self = bless { | |||||||||||||||||||
| 85 | prop => {}, | ||||||||||||||||||||
| 86 | %args, | ||||||||||||||||||||
| 87 | }, $class; | ||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | sub default | ||||||||||||||||||||
| 91 | 64 | ▶ | { | ||||||||||||||||||
|
Subroutine
default: called CC=2 SCAR=9.2
| |||||||||||||||||||||
| 92 | 64 | my($self) = @_; | |||||||||||||||||||
| 93 | 64 | ▶ | $self->{default} || do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | Carp::croak "No default for @{[ $self->{class} ]}"; | |||||||||||||||||||
| 95 | }; | ||||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | sub add_property | ||||||||||||||||||||
| 99 | 607 | ▶ | { | ||||||||||||||||||
|
Subroutine
add_property: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 100 | 607 | my($self, $name, $default) = @_; | |||||||||||||||||||
| 101 | 607 | my $single = $name =~ s{^(\+)}{}; | |||||||||||||||||||
| 102 | 607 | ▶ | $self->{default} = $name if $single; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | 607 | $self->{prop}->{$name} = $default; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 2436 | ▶ | my $accessor = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 106 | 2436 | my($self, $new) = @_; | |||||||||||||||||||
| 107 | 2436 | ▶ | $self->{$name} = $new if defined $new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 108 | 2436 | $self->{$name}; | |||||||||||||||||||
| 109 | 607 | }; | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | # add the accessor | ||||||||||||||||||||
| 112 | 68 | ▶ | { no strict 'refs'; *{ $self->{class} . '::' . $name} = $accessor } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 607 | $self; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | sub prop | ||||||||||||||||||||
| 118 | 3602 | ▶ | { | ||||||||||||||||||
|
Subroutine
prop: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 119 | 3602 | shift->{prop}; | |||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 68 | 1; | |||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | __END__ | ||||||||||||||||||||