| 1 | package Skilletor::Source::Local; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: A source read straight from a local directory (author mode) | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 34 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 34 | ▶ | use Skilletor::Error::Source; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 34 | ▶ | use Skilletor::FSUtil qw( path_join ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 34 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 34 | with 'Skilletor::Role::Source'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 34 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 34 | has local_path => ( | |||||||||||||||||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 34 | has home => ( | |||||||||||||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 34 | has dir => ( | |||||||||||||||||||||||||||||||||||||||||
| 23 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 201 | ▶ | sub _build_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_dir: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 201 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 201 | ▶ | return defined $self->home ? $self->expand_home( $self->local_path, $self->home ) : $self->local_path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # A leading ~ or ~/ against the home; other paths pass through. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 241 | ▶ | sub expand_home { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_home: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 241 | my ( $self, $path, $home ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 241 | ▶ | return $home if $path eq '~'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 240 | ▶ | return path_join( $home, substr( $path, 2 ) ) if $path =~ m{\A~/} || ( $^O eq 'MSWin32' && $path =~ m{\A~\\} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$path =~ m[\A~/] or $^O eq "MSWin32" and $path =~ /\A~\\/
$^O eq "MSWin32" and $path =~ /\A~\\/
MC/DC33%1/3
$path =~ m[\A~/] or $^O eq "MSWin32" and $path =~ /\A~\\/
$path =~ m[\A~/]
$^O eq "MSWin32"
$path =~ /\A~\\/
Truth table50%2/4
A or B and C
A= $path =~ m[\A~/]B= $^O eq "MSWin32"C= $path =~ /\A~\\/
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 234 | return $path; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | sub exists { -d $_[0]->dir ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 199 | ▶ | sub resolve { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 199 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 199 | ▶ | Skilletor::Error::Source->throw( 'local source directory does not exist: '.$self->dir ) unless -e $self->dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 198 | return { dir => $self->dir, version => 'local' }; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # No network to avoid: the directory itself. | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub cached { $_[0]->resolve } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cached: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # Local sources are always re-rendered. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 14 | ▶ | sub check { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 34 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||||||||||||||||||||