| 1 | package MooseX::Attributes::Curried; | ||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Sub::Exporter build_exporter => { -as => '_build_exporter' }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 6 | our $VERSION = 0.03; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # taken from Moose.pm, but level has been subtracted by one due to less | ||||||||||||||||||||||||||||
| 9 | # indirection | ||||||||||||||||||||||||||||
| 10 | 9 | ▶ | sub _caller_info { | ||||||||||||||||||||||||||
|
Subroutine
_caller_info: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 11 | 9 | ▶ | my $level = @_ ? $_[0] : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | 9 | my %info; | |||||||||||||||||||||||||||
| 13 | 9 | @info{qw(package file line)} = caller($level); | |||||||||||||||||||||||||||
| 14 | 9 | return \%info; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | sub build_exporter { | ||||||||||||||||||||||||||
|
Subroutine
build_exporter: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 6 | my %keywords; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 6 | ▶ | while (my ($keyword, $defaults) = splice @_, 0, 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 11 | ▶ | ref($defaults) eq 'HASH' || ref($defaults) eq 'CODE' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $defaults eq "HASH" or ref $defaults eq "CODE"
MC/DC0%0/2
ref $defaults eq "HASH" or ref $defaults eq "CODE"
ref $defaults eq "HASH"
ref $defaults eq "CODE"
Truth table66%2/3
A or B
A= ref $defaults eq "HASH"B= ref $defaults eq "CODE"
| |||||||||||||||||||||||||||||
| 22 | or Carp::croak("The defaults for '$keyword' must be a hashref or a coderef."); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 10 | ▶ | $keywords{$keyword} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 10 | my ($class, $arg, $opt) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 9 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 28 | 9 | my $name = shift; | |||||||||||||||||||||||||||
| 29 | my %options = ( | ||||||||||||||||||||||||||||
| 30 | definition_context => _caller_info(), | ||||||||||||||||||||||||||||
| 31 | 9 | ▶ | (ref($defaults) eq 'CODE' ? do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 2 | local $_ = $name; | |||||||||||||||||||||||||||
| 33 | 2 | %{ $defaults->($opt, [@_]) }, | |||||||||||||||||||||||||||
| 34 | } : (%$defaults, %$opt, @_)), | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 9 | ▶ | my $attrs = (ref($name) eq 'ARRAY') ? $name : [$name]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 9 | my $meta = Class::MOP::class_of(caller); | |||||||||||||||||||||||||||
| 40 | 9 | $meta->add_attribute($_, %options) for @$attrs; | |||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||
| 42 | 11 | }; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 6 | return _build_exporter({ | |||||||||||||||||||||||||||
| 46 | exports => [%keywords], | ||||||||||||||||||||||||||||
| 47 | groups => { | ||||||||||||||||||||||||||||
| 48 | default => [keys %keywords], | ||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||
| 50 | }); | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 6 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 6 | shift; | |||||||||||||||||||||||||||
| 55 | 6 | my $exporter = build_exporter(@_); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 6 | my $caller = caller; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 6 | *{ $caller . '::import' } = $exporter; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 6 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||