| 1 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 7 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Data::Couplet::Extension; | ||||||||||
| 5 | 7 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 7 | $Data::Couplet::Extension::AUTHORITY = 'cpan:KENTNL'; | |||||||||
| 7 | } | ||||||||||
| 8 | { | ||||||||||
| 9 | 7 | $Data::Couplet::Extension::VERSION = '0.02004314'; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | # ABSTRACT: A convenient way for sub classing Data::Couplet with minimal effort | ||||||||||
| 13 | |||||||||||
| 14 | 7 | ▶ | use MooseX::Types::Moose qw( :all ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 7 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub _dump { | ||||||||
|
Subroutine
_dump: not called CC=1 SCAR=6.9
| |||||||||||
| 19 | 0 | my (@args) = @_; | |||||||||
| 20 | 0 | require Data::Dumper; | |||||||||
| 21 | 0 | local $Data::Dumper::Terse = 1; | |||||||||
| 22 | 0 | local $Data::Dumper::Indent = 0; | |||||||||
| 23 | 0 | local $Data::Dumper::Maxdepth = 1; | |||||||||
| 24 | 0 | local $Data::Dumper::Quotekeys = 0; | |||||||||
| 25 | 0 | return Data::Dumper::Dumper(@args); | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub _carp_key { | ||||||||
|
Subroutine
_carp_key: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | 0 | my ( $key, $config, $message ) = @_; | |||||||||
| 30 | 0 | carp( sprintf '%s => %s %s', $key, _dump( $config->{$key} ), $message ); | |||||||||
| 31 | 0 | return; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub _croak_key { | ||||||||
|
Subroutine
_croak_key: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | 0 | my ( $key, $config, $message ) = @_; | |||||||||
| 36 | 0 | croak( sprintf '%s => %s %s', $key, _dump( $config->{$key} ), $message ); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | 6 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=16 SCAR=30.1
| |||||||||||
| 41 | 6 | my ( $class, @args ) = @_; | |||||||||
| 42 | 6 | my (%config) = (@args); | |||||||||
| 43 | 6 | my $caller = caller; | |||||||||
| 44 | |||||||||||
| 45 | 6 | require Moose; | |||||||||
| 46 | 6 | require Data::Couplet::Private; | |||||||||
| 47 | 6 | require Data::Couplet::Role::Plugin; | |||||||||
| 48 | |||||||||||
| 49 | 6 | ▶ | $config{-into} = $caller unless exists $config{-into}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | #_croak_key( -into => \%config, 'target is not a valid ClassName' ) unless is_ClassName( $config{-into} ); | ||||||||||
| 52 | |||||||||||
| 53 | 6 | ▶ | if ( $config{-into} eq 'main' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | _carp_key( -into => \%config, '<-- is main, not injecting' ); | |||||||||
| 55 | 0 | return; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 6 | ▶ | $config{-base} = q{} unless exists $config{-base}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | |||||||||||
| 60 | 6 | ▶ | _croak_key( -base => \%config, 'is not a Str' ) unless is_Str( $config{-base} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 6 | $config{-base_package} = 'Data::Couplet'; | |||||||||
| 63 | 6 | ▶ | if ( $config{-base} ne q{} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 6 | $config{-base_package} = 'Data::Couplet::' . $config{-base}; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 6 | ▶ | if ( $config{-base_package} eq 'Data::Couplet' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | require Data::Couplet; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | _croak_key( -base_package => \%config, 'is not a valid ClassName' ) | ||||||||||
| 72 | 6 | ▶ | unless is_ClassName( $config{-base_package} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | |||||||||||
| 74 | 6 | ▶ | $config{-with} = [] unless exists $config{-with}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 6 | $config{-with_expanded} = []; | |||||||||
| 76 | |||||||||||
| 77 | 6 | ▶ | _croak_key( -with => \%config, 'is not an ArrayRef' ) unless is_ArrayRef( $config{-with} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 6 | for ( @{ $config{-with} } ) { | |||||||||
| 79 | 12 | my $plugin = 'Data::Couplet::Plugin::' . $_; | |||||||||
| 80 | 12 | ▶ | eval "require $plugin; 1" or croak("Could not load Data::Couplet plugin $plugin"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 12 | ▶ | croak("plugin $plugin loaded, but still seems not to be a valid ClassName") unless is_ClassName($plugin); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 12 | ▶ | croak("plugin $plugin cant meta") unless $plugin->can('meta'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 12 | ▶ | croak("plugin $plugin meta cant does_role") unless $plugin->meta->can('does_role'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 12 | ▶ | croak("plugin $plugin doesn't do DC::R:P") unless $plugin->meta->does_role('Data::Couplet::Role::Plugin'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 12 | push @{ $config{-with_expanded} }, $plugin; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | # Input validation and expansion et-all complete. | ||||||||||
| 89 | # Inject warnings/strict for caller. | ||||||||||
| 90 | 6 | strict->import(); | |||||||||
| 91 | 6 | warnings->import(); | |||||||||
| 92 | 6 | Moose->import( { into => $config{-into}, } ); | |||||||||
| 93 | 6 | $config{-into}->can('extends')->( $config{-base_package} ); | |||||||||
| 94 | 6 | $config{-into}->can('with')->( @{ $config{-with_expanded} } ); | |||||||||
| 95 | 6 | return; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | |||||||||||
| 99 | 6 | ▶ | sub unimport { | ||||||||
|
Subroutine
unimport: called CC=1 SCAR=0.0
| |||||||||||
| 100 | |||||||||||
| 101 | # Sub Optimal, but cant be avoided atm because Moose lacks | ||||||||||
| 102 | # A 3rd-Party friendly unimport | ||||||||||
| 103 | 6 | goto \&Moose::unimport; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 7 | 1; | |||||||||
| 107 | |||||||||||
| 108 | |||||||||||
| 109 | __END__ | ||||||||||