| 1 | 4 | ▶ | use 5.006; # pragmas | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Test::File::ShareDir::TempDirObject; | ||||||||||
| 6 | |||||||||||
| 7 | 4 | our $VERSION = '1.001002'; | |||||||||
| 8 | |||||||||||
| 9 | # ABSTRACT: Internal Object to make code simpler. | ||||||||||
| 10 | |||||||||||
| 11 | 4 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | 4 | ▶ | use Path::Tiny qw(path); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 4 | ▶ | use Carp qw(confess); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | ## no critic (Subroutines::RequireArgUnpacking) | ||||||||||
| 27 | 3 | ▶ | sub __rcopy { require File::Copy::Recursive; goto \&File::Copy::Recursive::rcopy; } | ||||||||
|
Subroutine
__rcopy: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | 3 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||
| 36 | 3 | my ( $class, $config ) = @_; | |||||||||
| 37 | |||||||||||
| 38 | 3 | ▶ | confess('Need -share => for Test::File::ShareDir') unless exists $config->{-share}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | 3 | my $realconfig = { | |||||||||
| 41 | root => path(q{./})->absolute, #->resolve->absolute, | ||||||||||
| 42 | modules => {}, | ||||||||||
| 43 | dists => {}, | ||||||||||
| 44 | }; | ||||||||||
| 45 | |||||||||||
| 46 | 3 | ▶ | $realconfig->{root} = path( delete $config->{-root} )->absolute if exists $config->{-root}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 3 | ▶ | $realconfig->{modules} = delete $config->{-share}->{-module} if exists $config->{-share}->{-module}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 3 | ▶ | $realconfig->{dists} = delete $config->{-share}->{-dist} if exists $config->{-share}->{-dist}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | confess( 'Unsupported -share types : ' . join q{ }, keys %{ $config->{-share} } ) if keys %{ $config->{-share} }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 3 | delete $config->{-share}; | |||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | confess( 'Unsupported parameter to import() : ' . join q{ }, keys %{$config} ) if keys %{$config}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 3 | return bless $realconfig, $class; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 4 | my @cache; | |||||||||
| 60 | |||||||||||
| 61 | 6 | ▶ | sub _tempdir { | ||||||||
|
Subroutine
_tempdir: called CC=2 SCAR=6.9
| |||||||||||
| 62 | 6 | my ($self) = shift; | |||||||||
| 63 | 6 | ▶ | return $self->{tempdir} if exists $self->{tempdir}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 3 | $self->{tempdir} = Path::Tiny::tempdir( CLEANUP => 1 ); | |||||||||
| 65 | |||||||||||
| 66 | # Explicit keepalive till GC | ||||||||||
| 67 | 3 | push @cache, $self->{tempdir}; | |||||||||
| 68 | 3 | return $self->{tempdir}; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 2 | ▶ | sub _module_tempdir { | ||||||||
|
Subroutine
_module_tempdir: called CC=2 SCAR=7.0
| |||||||||||
| 72 | 2 | my ($self) = shift; | |||||||||
| 73 | 2 | ▶ | return $self->{module_tempdir} if exists $self->{module_tempdir}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 2 | $self->{module_tempdir} = $self->_tempdir->child('auto/share/module'); | |||||||||
| 75 | 2 | $self->{module_tempdir}->mkpath(); | |||||||||
| 76 | 2 | return $self->{module_tempdir}->absolute; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 1 | ▶ | sub _dist_tempdir { | ||||||||
|
Subroutine
_dist_tempdir: called CC=2 SCAR=7.0
| |||||||||||
| 80 | 1 | my ($self) = shift; | |||||||||
| 81 | 1 | ▶ | return $self->{dist_tempdir} if exists $self->{dist_tempdir}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 1 | $self->{dist_tempdir} = $self->_tempdir->child('auto/share/dist'); | |||||||||
| 83 | 1 | $self->{dist_tempdir}->mkpath(); | |||||||||
| 84 | 1 | return $self->{dist_tempdir}->absolute; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 3 | ▶ | sub _root { | ||||||||
|
Subroutine
_root: called CC=1 SCAR=0.0
| |||||||||||
| 88 | 3 | my ($self) = shift; | |||||||||
| 89 | 3 | return $self->{root}; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 5 | ▶ | sub _modules { return shift->{modules}; } | ||||||||
|
Subroutine
_modules: called CC=1 SCAR=0.0
| |||||||||||
| 93 | |||||||||||
| 94 | 4 | ▶ | sub _dists { return shift->{dists} } | ||||||||
|
Subroutine
_dists: called CC=1 SCAR=0.0
| |||||||||||
| 95 | |||||||||||
| 96 | 3 | ▶ | sub _module_names { | ||||||||
|
Subroutine
_module_names: called CC=1 SCAR=0.0
| |||||||||||
| 97 | 3 | my ($self) = shift; | |||||||||
| 98 | 3 | return keys %{ $self->_modules }; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 3 | ▶ | sub _dist_names { | ||||||||
|
Subroutine
_dist_names: called CC=1 SCAR=0.0
| |||||||||||
| 102 | 3 | my ($self) = shift; | |||||||||
| 103 | 3 | return keys %{ $self->_dists }; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 2 | ▶ | sub _module_share_target_dir { | ||||||||
|
Subroutine
_module_share_target_dir: called CC=1 SCAR=0.0
| |||||||||||
| 107 | 2 | my ( $self, $modname ) = @_; | |||||||||
| 108 | |||||||||||
| 109 | ## no critic (RegularExpressions) | ||||||||||
| 110 | 2 | $modname =~ s/::/-/g; | |||||||||
| 111 | |||||||||||
| 112 | 2 | return $self->_module_tempdir->child($modname); | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | 1 | ▶ | sub _dist_share_target_dir { | ||||||||
|
Subroutine
_dist_share_target_dir: called CC=1 SCAR=0.0
| |||||||||||
| 116 | 1 | my ( $self, $distname ) = @_; | |||||||||
| 117 | 1 | return $self->_dist_tempdir->child($distname); | |||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | 2 | ▶ | sub _module_share_source_dir { | ||||||||
|
Subroutine
_module_share_source_dir: called CC=1 SCAR=0.0
| |||||||||||
| 121 | 2 | my ( $self, $module ) = @_; | |||||||||
| 122 | 2 | return path( $self->_modules->{$module} )->absolute( $self->_root ); | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 1 | ▶ | sub _dist_share_source_dir { | ||||||||
|
Subroutine
_dist_share_source_dir: called CC=1 SCAR=0.0
| |||||||||||
| 126 | 1 | my ( $self, $dist ) = @_; | |||||||||
| 127 | 1 | return path( $self->_dists->{$dist} )->absolute( $self->_root ); | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | 2 | ▶ | sub _install_module { | ||||||||
|
Subroutine
_install_module: called CC=1 SCAR=0.0
| |||||||||||
| 131 | 2 | my ( $self, $module ) = @_; | |||||||||
| 132 | 2 | return __rcopy( $self->_module_share_source_dir($module), $self->_module_share_target_dir($module) ); | |||||||||
| 133 | } | ||||||||||
| 134 | |||||||||||
| 135 | 1 | ▶ | sub _install_dist { | ||||||||
|
Subroutine
_install_dist: called CC=1 SCAR=0.0
| |||||||||||
| 136 | 1 | my ( $self, $dist ) = @_; | |||||||||
| 137 | 1 | return __rcopy( $self->_dist_share_source_dir($dist), $self->_dist_share_target_dir($dist) ); | |||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | 4 | 1; | |||||||||
| 141 | |||||||||||
| 142 | __END__ | ||||||||||