| 1 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Dist::Zilla::lsplugins::Module; | ||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '0.003001'; | |||||||||
| 8 | |||||||||||
| 9 | # ABSTRACT: Transient data about a traversed plugin/role/module | ||||||||||
| 10 | |||||||||||
| 11 | 1 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use Moose qw( has ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use Try::Tiny qw( try catch ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 1 | has 'file' => ( is => ro =>, required => 1 ); | |||||||||
| 17 | 1 | has 'plugin_root' => ( is => ro =>, required => 1 ); | |||||||||
| 18 | 1 | has 'plugin_basename' => ( is => ro =>, required => 1 ); | |||||||||
| 19 | 1 | has 'plugin_name' => ( is => ro =>, lazy_build => 1 ); | |||||||||
| 20 | 1 | has '_version' => ( is => ro =>, lazy_build => 1 ); | |||||||||
| 21 | 1 | has 'version' => ( is => ro =>, lazy_build => 1 ); | |||||||||
| 22 | 1 | has 'abstract' => ( is => ro =>, lazy_build => 1 ); | |||||||||
| 23 | 1 | has 'roles' => ( is => ro =>, lazy_build => 1 ); | |||||||||
| 24 | 1 | has '_module_metadata' => ( is => ro =>, lazy_build => 1 ); | |||||||||
| 25 | 1 | has '_loaded_module' => ( is => ro =>, lazy_build => 1 ); | |||||||||
| 26 | |||||||||||
| 27 | 0 | ▶ | sub _build_plugin_name { | ||||||||
|
Subroutine
_build_plugin_name: not called CC=1 SCAR=6.9
| |||||||||||
| 28 | 0 | my ($self) = @_; | |||||||||
| 29 | 0 | my $rpath = $self->file->relative( $self->plugin_root ); | |||||||||
| 30 | 0 | $rpath =~ s/[.]pm\z//msx; | |||||||||
| 31 | 0 | $rpath =~ s{/}{::}gmsx; | |||||||||
| 32 | 0 | return $rpath; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub _build_version { | ||||||||
|
Subroutine
_build_version: not called CC=2 SCAR=17.9
| |||||||||||
| 36 | 0 | my ($self) = @_; | |||||||||
| 37 | 0 | my $v = $self->_version; | |||||||||
| 38 | 0 | ▶ | return $v if defined $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | return 'undef'; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub _build__module_metadata { | ||||||||
|
Subroutine
_build__module_metadata: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | 0 | my ($self) = @_; | |||||||||
| 44 | 0 | require Module::Metadata; | |||||||||
| 45 | 0 | return Module::Metadata->new_from_file( $self->file ); | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub _build__version { | ||||||||
|
Subroutine
_build__version: not called CC=1 SCAR=6.9
| |||||||||||
| 49 | 0 | my ($self) = @_; | |||||||||
| 50 | 0 | return $self->_module_metadata->version; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | sub _build_abstract { | ||||||||
|
Subroutine
_build_abstract: not called CC=1 SCAR=6.9
| |||||||||||
| 54 | 0 | my ($self) = @_; | |||||||||
| 55 | 0 | require Dist::Zilla::Util; | |||||||||
| 56 | ## no critic ( Subroutines::ProtectPrivateSubs ) | ||||||||||
| 57 | 0 | my $e = Dist::Zilla::Util::PEA->_new(); | |||||||||
| 58 | 0 | $e->read_file( $self->file->stringify ); | |||||||||
| 59 | 0 | return $e->{abstract}; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | sub _build__loaded_module { | ||||||||
|
Subroutine
_build__loaded_module: not called CC=2 SCAR=17.9
| |||||||||||
| 63 | 0 | my ($self) = @_; | |||||||||
| 64 | 0 | require Module::Runtime; | |||||||||
| 65 | 0 | my $module = $self->plugin_basename . q[::] . $self->plugin_name; | |||||||||
| 66 | 0 | my $failed = 0; | |||||||||
| 67 | 0 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 68 | 0 | Module::Runtime::require_module($module); | |||||||||
| 69 | } | ||||||||||
| 70 | 0 | ▶ | catch { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | 0 | require Carp; | |||||||||
| 72 | 0 | Carp::carp( q[Uhoh, ] . $module . q[ failed to load] ); | |||||||||
| 73 | ## no critic (ErrorHandling::RequireCarping) | ||||||||||
| 74 | 0 | warn $_; | |||||||||
| 75 | 0 | $failed = 1; | |||||||||
| 76 | 0 | }; | |||||||||
| 77 | 0 | ▶ | return if $failed; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | return $module; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | sub _build_roles { | ||||||||
|
Subroutine
_build_roles: not called CC=5 SCAR=34.0
| |||||||||||
| 82 | 0 | my ($self) = @_; | |||||||||
| 83 | 0 | my $module = $self->_loaded_module(); | |||||||||
| 84 | 0 | ▶ | return [] if not defined $module; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 0 | ▶ | return [] if not $module->can('meta'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | ▶ | return [] if not $module->meta->can('calculate_all_roles_with_inheritance'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | my @roles = $module->meta->calculate_all_roles_with_inheritance; | |||||||||
| 88 | 0 | my @out; | |||||||||
| 89 | 0 | for my $role (@roles) { | |||||||||
| 90 | 0 | push @out, $role->name; | |||||||||
| 91 | } | ||||||||||
| 92 | 0 | return \@out; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | |||||||||||
| 96 | |||||||||||
| 97 | |||||||||||
| 98 | |||||||||||
| 99 | |||||||||||
| 100 | |||||||||||
| 101 | |||||||||||
| 102 | |||||||||||
| 103 | |||||||||||
| 104 | 0 | ▶ | sub loaded_module_does { | ||||||||
|
Subroutine
loaded_module_does: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 105 | 0 | my ( $self, $role ) = @_; | |||||||||
| 106 | 0 | $role =~ s/\A-/Dist::Zilla::Role::/msx; | |||||||||
| 107 | 0 | ▶ | return unless $self->_loaded_module; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 0 | ▶ | return unless $self->_loaded_module->can('does'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 0 | return $self->_loaded_module->does($role); | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 113 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 114 | 1 | 1; | |||||||||
| 115 | |||||||||||
| 116 | __END__ | ||||||||||