| 1 | package CPAN::Local; | ||||||||||
| 2 | { | ||||||||||
| 3 | 2 | $CPAN::Local::VERSION = '0.010'; | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Hack custom CPAN repos | ||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use Path::Class qw(file dir); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use File::Path qw(make_path); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use List::MoreUtils qw(uniq apply); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use Class::Load qw(load_class); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 2 | ▶ | use File::Copy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 2 | ▶ | use CPAN::Local::MVP::Assembler; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | ▶ | use Config::MVP::Reader::Finder; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use Log::Dispatchouli; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | ▶ | use Moose::Meta::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 2 | has 'config' => ( | |||||||||
| 25 | is => 'ro', | ||||||||||
| 26 | required => 1, | ||||||||||
| 27 | lazy_build => 1, | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 2 | has 'root' => ( | |||||||||
| 31 | is => 'ro', | ||||||||||
| 32 | isa => 'Str', | ||||||||||
| 33 | required => 1, | ||||||||||
| 34 | default => '.', | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | 2 | has 'root_namespace' => | |||||||||
| 38 | ( | ||||||||||
| 39 | is => 'ro', | ||||||||||
| 40 | isa => 'Str', | ||||||||||
| 41 | required => 1, | ||||||||||
| 42 | default => 'CPAN::Local', | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | 2 | has 'plugins' => ( | |||||||||
| 46 | is => 'ro', | ||||||||||
| 47 | isa => 'HashRef', | ||||||||||
| 48 | required => 1, | ||||||||||
| 49 | lazy_build => 1, | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | 2 | has 'config_filename' => | |||||||||
| 53 | ( | ||||||||||
| 54 | is => 'ro', | ||||||||||
| 55 | isa => 'Str', | ||||||||||
| 56 | required => 1, | ||||||||||
| 57 | default => 'cpanlocal' | ||||||||||
| 58 | ); | ||||||||||
| 59 | |||||||||||
| 60 | 2 | has 'logger' => | |||||||||
| 61 | ( | ||||||||||
| 62 | is => 'ro', | ||||||||||
| 63 | isa => 'Log::Dispatchouli', | ||||||||||
| 64 | lazy_build => 1, | ||||||||||
| 65 | ); | ||||||||||
| 66 | |||||||||||
| 67 | 2 | has 'distribution_base_class' => | |||||||||
| 68 | ( | ||||||||||
| 69 | is => 'ro', | ||||||||||
| 70 | isa => 'Str', | ||||||||||
| 71 | default => 'CPAN::Local::Distribution', | ||||||||||
| 72 | ); | ||||||||||
| 73 | |||||||||||
| 74 | sub plugins_with | ||||||||||
| 75 | 0 | ▶ | { | ||||||||
|
Subroutine
plugins_with: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 76 | 0 | my ($self, $role) = @_; | |||||||||
| 77 | |||||||||||
| 78 | 0 | my $role_class = $self->root_namespace . '::Role::'; | |||||||||
| 79 | 0 | $role =~ s/^-/$role_class/; | |||||||||
| 80 | |||||||||||
| 81 | 0 | my @plugins = grep { $_->does($role) } values %{ $self->plugins }; | |||||||||
| 82 | 0 | return @plugins; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | sub _build_logger | ||||||||||
| 86 | 0 | ▶ | { | ||||||||
|
Subroutine
_build_logger: not called CC=1 SCAR=6.9
| |||||||||||
| 87 | 0 | return Log::Dispatchouli->new({ | |||||||||
| 88 | ident => 'CPAN::Local', | ||||||||||
| 89 | to_stdout => 1, | ||||||||||
| 90 | log_pid => 0, | ||||||||||
| 91 | quiet_fatal => 'stdout', | ||||||||||
| 92 | }); | ||||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | sub _build_config | ||||||||||
| 96 | 0 | ▶ | { | ||||||||
|
Subroutine
_build_config: not called CC=1 SCAR=6.9
| |||||||||||
| 97 | 0 | my $self = shift; | |||||||||
| 98 | |||||||||||
| 99 | 0 | my $location = file( $self->root, $self->config_filename )->stringify; | |||||||||
| 100 | |||||||||||
| 101 | 0 | my $assembler = CPAN::Local::MVP::Assembler->new( | |||||||||
| 102 | root_namespace => $self->root_namespace, | ||||||||||
| 103 | ); | ||||||||||
| 104 | |||||||||||
| 105 | 0 | return Config::MVP::Reader::Finder->read_config( | |||||||||
| 106 | $location, { assembler => $assembler } | ||||||||||
| 107 | ); | ||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | sub _build_plugins | ||||||||||
| 111 | 0 | ▶ | { | ||||||||
|
Subroutine
_build_plugins: not called CC=4 SCAR=30.0
| |||||||||||
| 112 | 0 | my $self = shift; | |||||||||
| 113 | |||||||||||
| 114 | 0 | my ( %sections, %plugins, @disribution_roles ); | |||||||||
| 115 | |||||||||||
| 116 | 0 | my $distribution_class = $self->distribution_base_class; | |||||||||
| 117 | |||||||||||
| 118 | 0 | my $role_prefix = "CPAN::Local::Distribution::Role::"; | |||||||||
| 119 | |||||||||||
| 120 | my @distribution_roles = | ||||||||||
| 121 | 0 | map { "$role_prefix$_" } | |||||||||
| 122 | 0 | uniq map { $_->package->requires_distribution_roles } | |||||||||
| 123 | 0 | ▶ | apply { load_class $_->package } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 124 | 0 | $self->config->sections; | |||||||||
| 125 | |||||||||||
| 126 | 0 | ▶ | if ( @distribution_roles ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | { | ||||||||||
| 128 | 0 | ▶ | $distribution_class = Moose::Meta::Class->create_anon_class( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | superclasses => [$self->distribution_base_class], | ||||||||||
| 130 | cache => 1, | ||||||||||
| 131 | @distribution_roles ? ( roles => \@distribution_roles ) : (), | ||||||||||
| 132 | )->name; | ||||||||||
| 133 | } | ||||||||||
| 134 | |||||||||||
| 135 | 0 | for my $section ($self->config->sections) | |||||||||
| 136 | { | ||||||||||
| 137 | my $plugin = $section->package->new( | ||||||||||
| 138 | 0 | %{ $section->payload }, | |||||||||
| 139 | root => $self->root, | ||||||||||
| 140 | logger => $self->logger->proxy({ | ||||||||||
| 141 | proxy_prefix => "[" . $section->name . "] " | ||||||||||
| 142 | }), | ||||||||||
| 143 | distribution_class => $distribution_class, | ||||||||||
| 144 | ); | ||||||||||
| 145 | 0 | $plugins{$section->name} = $plugin; | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | 0 | return \%plugins; | |||||||||
| 149 | } | ||||||||||
| 150 | |||||||||||
| 151 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 152 | |||||||||||
| 153 | |||||||||||
| 154 | __END__ | ||||||||||