| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Moose::Micro; | ||||||||||
| 5 | 2 | our $VERSION = '0.002'; | |||||||||
| 6 | |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Moose (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Moose::Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use B::Hooks::EndOfScope; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | my ($import, $unimport); | |||||||||
| 13 | 2 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ($import, $unimport) = Moose::Exporter->build_import_methods( | |||||||||
| 15 | also => 'Moose', | ||||||||||
| 16 | ); | ||||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 2 | my $class = shift; | |||||||||
| 21 | 2 | my $attributes = shift; | |||||||||
| 22 | |||||||||||
| 23 | 2 | my $caller = caller; | |||||||||
| 24 | |||||||||||
| 25 | 2 | ▶ | on_scope_end { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 26 | 2 | my $meta = Moose::Meta::Class->initialize($caller); | |||||||||
| 27 | 2 | $meta->add_attribute(@$_) for $class->attribute_list($caller, $attributes); | |||||||||
| 28 | 2 | }; | |||||||||
| 29 | |||||||||||
| 30 | 2 | unshift @_, $class; | |||||||||
| 31 | 2 | goto &$import; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub unimport { goto &$unimport } | ||||||||
|
Subroutine
unimport: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | |||||||||||
| 36 | 2 | ▶ | sub attribute_list { | ||||||||
|
Subroutine
attribute_list: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 37 | 2 | my ($self, $pkg, $attributes) = @_; | |||||||||
| 38 | |||||||||||
| 39 | 2 | my @attributes; | |||||||||
| 40 | |||||||||||
| 41 | 2 | my ($required, $optional) = split /\s*;\s*/, $attributes; | |||||||||
| 42 | |||||||||||
| 43 | 2 | for my $attr (grep { length } split /\s+/, $required) { | |||||||||
| 44 | 2 | my ($name, %args) = $self->attribute_args($pkg, $attr); | |||||||||
| 45 | 2 | $args{required} = 1; | |||||||||
| 46 | 2 | push @attributes, [ $name, %args ]; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 2 | for my $attr (grep { length } split /\s+/, $optional) { | |||||||||
| 50 | 3 | my ($name, %args) = $self->attribute_args($pkg, $attr); | |||||||||
| 51 | 3 | push @attributes, [ $name, %args ]; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 2 | return @attributes; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 5 | ▶ | sub attribute_args { | ||||||||
|
Subroutine
attribute_args: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 58 | 5 | my ($self, $pkg, $attribute) = @_; | |||||||||
| 59 | |||||||||||
| 60 | 5 | my %args = ( | |||||||||
| 61 | is => 'rw', | ||||||||||
| 62 | ); | ||||||||||
| 63 | |||||||||||
| 64 | 5 | ▶ | if ($attribute =~ s/^([\$\@\%])//) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 4 | my $type = $1; | |||||||||
| 66 | 4 | %args = (%args, $self->type_constraint_for($type)); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 5 | ▶ | if ($attribute =~ s/^\!//) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 1 | %args = (%args, accessor => "_$attribute"); | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 5 | ▶ | if ($pkg->can("_build_$attribute")) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 1 | $args{lazy_build} = 1; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 5 | return ($attribute => %args); | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 2 | my %TC = ( | |||||||||
| 81 | '$' => 'Value|ScalarRef|CodeRef|RegexpRef|GlobRef|Object', | ||||||||||
| 82 | '@' => 'ArrayRef', | ||||||||||
| 83 | '%' => 'HashRef', | ||||||||||
| 84 | ); | ||||||||||
| 85 | |||||||||||
| 86 | 4 | ▶ | sub type_constraint_for { | ||||||||
|
Subroutine
type_constraint_for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 87 | 4 | my ($self, $sigil) = @_; | |||||||||
| 88 | |||||||||||
| 89 | 4 | return (isa => $TC{$sigil}); | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 2 | 1; | |||||||||
| 93 | |||||||||||
| 94 | __END__ | ||||||||||