| 1 | package MOP::Method::Attribute; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: The Method Attribute object | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 33 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 33 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 33 | our $VERSION = '0.14'; | |||||||||||||||||||||||||||
| 10 | 33 | our $AUTHORITY = 'cpan:STEVAN'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 33 | ▶ | use parent 'UNIVERSAL::Object::Immutable'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 33 | ▶ | our %HAS; BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||
| 15 | %HAS = ( | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | original => sub { die '`original` is required' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 17 | ) | ||||||||||||||||||||||||||||
| 18 | 33 | } | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # NOTE: | ||||||||||||||||||||||||||||
| 21 | # we are not terribly sophisticated, but | ||||||||||||||||||||||||||||
| 22 | # we accept `foo` calls (no-parens) and | ||||||||||||||||||||||||||||
| 23 | # we accept `foo(1, 2, 3)` calls (parens | ||||||||||||||||||||||||||||
| 24 | # with comma seperated args). | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 28 | 2 | ▶ | Carp::confess('You must pass only a simple string') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @_ == 1 and not ref $_[0]
MC/DC0%0/2
scalar @_ == 1 and not ref $_[0]
scalar @_ == 1
not ref $_[0]
Truth table33%1/3
A and not(B)
A= scalar @_ == 1B= not ref $_[0]
| |||||||||||||||||||||||||||||
| 29 | unless scalar(@_) == 1 && not ref $_[0]; | ||||||||||||||||||||||||||||
| 30 | 2 | return +{ original => $_[0] }; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | ▶ | sub REPR { \(my $x) } | ||||||||||||||||||||||||||
|
Subroutine
REPR: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | sub CREATE { | ||||||||||||||||||||||||||
|
Subroutine
CREATE: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 2 | my ($class, $proto) = @_; | |||||||||||||||||||||||||||
| 37 | 2 | my $self = $class->REPR; | |||||||||||||||||||||||||||
| 38 | 2 | $$self = $proto->{original}; | |||||||||||||||||||||||||||
| 39 | 2 | $self; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | sub original { ${ $_[0] } } | ||||||||||||||||||||||||||
|
Subroutine
original: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 46 | 2 | my ($name) = ($$self =~ m/^([a-zA-Z_]*)/); | |||||||||||||||||||||||||||
| 47 | 2 | return $name; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub args { | ||||||||||||||||||||||||||
|
Subroutine
args: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 1 | my ($self, $arg_splitter, $arg_processor) = @_; | |||||||||||||||||||||||||||
| 52 | 1 | my ($args) = ($$self =~ m/^[a-zA-Z_]*\(\s*(.*)\)/ms); | |||||||||||||||||||||||||||
| 53 | 1 | ▶ | return unless $args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # NOTE: | ||||||||||||||||||||||||||||
| 56 | # These parses arguments badly, | ||||||||||||||||||||||||||||
| 57 | # but they are just the defaults. | ||||||||||||||||||||||||||||
| 58 | # it makes no attempt to enforce | ||||||||||||||||||||||||||||
| 59 | # anything, just splits on the | ||||||||||||||||||||||||||||
| 60 | # comma, both skinny and fat, | ||||||||||||||||||||||||||||
| 61 | # then strips away any quotes | ||||||||||||||||||||||||||||
| 62 | # and treats everything as a | ||||||||||||||||||||||||||||
| 63 | # simple string. | ||||||||||||||||||||||||||||
| 64 | 1 | ▶ | $arg_splitter ||= sub { split /\s*(?:\,|\=\>)\s*/ => $_[0] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$arg_splitter ||= sub {
split(/\s*(?:\,|\=\>)\s*/, $_[0], 0);
}
MC/DC0%0/2
$arg_splitter ||= sub {
split(/\s*(?:\,|\=\>)\s*/, $_[0], 0);
}
$arg_splitter
sub {
split(/\s*(?:\,|\=\>)\s*/, $_[0], 0);
}
Truth table33%1/3
A ||= B
A= $arg_splitterB= sub {
split(/\s*(?:\,|\=\>)\s*/, $_[0], 0);
}
| |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | $arg_processor ||= sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 66 | # NOTE: | ||||||||||||||||||||||||||||
| 67 | # None of the args are eval-ed and they are | ||||||||||||||||||||||||||||
| 68 | # basically just a list of strings, with the | ||||||||||||||||||||||||||||
| 69 | # one exception of the string "undef", which | ||||||||||||||||||||||||||||
| 70 | # will be turned into undef | ||||||||||||||||||||||||||||
| 71 | 2 | my $arg = $_[0]; | |||||||||||||||||||||||||||
| 72 | 2 | $arg =~ s/\s*$//; | |||||||||||||||||||||||||||
| 73 | 2 | $arg =~ s/^['"]//; | |||||||||||||||||||||||||||
| 74 | 2 | $arg =~ s/['"]$//; | |||||||||||||||||||||||||||
| 75 | 2 | ▶ | $arg eq 'undef' ? undef : $arg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | }; | ||||||||||||||||||||||||||
|
Condition33%1/3
$arg_processor ||= sub {
my $arg = $_[0];
$arg =~ s/\s*$//;
$arg =~ s/^['"]//;
$arg =~ s/['"]$//;
$arg eq "undef" ? undef : $arg;
}
MC/DC0%0/2
$arg_processor ||= sub {
my $arg = $_[0];
$arg =~ s/\s*$//;
$arg =~ s/^['"]//;
$arg =~ s/['"]$//;
$arg eq "undef" ? undef : $arg;
}
$arg_processor
sub {
my $arg = $_[0];
$arg =~ s/\s*$//;
$arg =~ s/^['"]//;
$arg =~ s/['"]$//;
$arg eq "undef" ? undef : $arg;
}
Truth table33%1/3
A ||= B
A= $arg_processorB= sub {
my $arg = $_[0];
$arg =~ s/\s*$//;
$arg =~ s/^['"]//;
$arg =~ s/['"]$//;
$arg eq "undef" ? undef : $arg;
}
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | return [ map $arg_processor->( $_ ), $arg_splitter->( $args ) ]; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 33 | 1; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||