| 1 | 16 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 2 | 16 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 3 | |||||||||||||||||||
| 4 | package App::Embra::File; | ||||||||||||||||||
| 5 | 16 | $App::Embra::File::VERSION = '0.001'; # TRIAL | |||||||||||||||||
| 6 | # ABSTRACT: a file from your site | ||||||||||||||||||
| 7 | |||||||||||||||||||
| 8 | 16 | ▶ | use File::Basename; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | 16 | ▶ | use File::Spec::Functions qw< canonpath >; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | 16 | ▶ | use Method::Signatures; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 16 | ▶ | use Moo; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | # mostly Dist::Zilla::File::OnDisk | ||||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 16 | ▶ | use overload fallback => 1, | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=4 SCAR=14.1
Branch: 3 branches
| |||||||||||||||||||
| 17 | '""' => method( $other, $swap ) { $self->name }; | ||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | 16 | ||||||||||||||||||
| 20 | has 'name' => ( | ||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||
| 23 | ); | ||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 0 | ▶ | |||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||
| 26 | 16 | has 'content' => ( | |||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||
| 28 | lazy => 1, | ||||||||||||||||||
| 29 | 2 | ▶ | default => method { $self->_read_file }, | ||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||
| 30 | 16 | ); | |||||||||||||||||
| 31 | |||||||||||||||||||
| 32 | |||||||||||||||||||
| 33 | 16 | has 'mode' => ( | |||||||||||||||||
| 34 | is => 'rw', | ||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||
| 36 | default => method { oct(644) }, | ||||||||||||||||||
| 37 | ); | ||||||||||||||||||
| 38 | |||||||||||||||||||
| 39 | 34 | ▶ | |||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||
| 40 | 16 | has '_original_name' => ( | |||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||
| 42 | init_arg => undef, | ||||||||||||||||||
| 43 | 16 | ); | |||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | has 'notes' => ( | ||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||
| 48 | default => method { {} }, | ||||||||||||||||||
| 49 | ); | ||||||||||||||||||
| 50 | 16 | ▶ | |||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_split_name: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||
| 51 | 14 | ||||||||||||||||||
| 52 | has 'ext' => ( | ||||||||||||||||||
| 53 | is => 'rw', | ||||||||||||||||||
| 54 | 16 | ▶ | lazy => 1, | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
_build_ext: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||
| 55 | 11 | builder => 1, | |||||||||||||||||
| 56 | trigger => 1, | ||||||||||||||||||
| 57 | ); | ||||||||||||||||||
| 58 | |||||||||||||||||||
| 59 | 16 | ▶ | method _split_name { | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
with_ext: called CC=4 SCAR=14.1
Branch: 2 branches
| |||||||||||||||||||
| 60 | 3 | fileparse( $self->name, qr{ (?<= [.] ) [^.]+ $ }x ); | |||||||||||||||||
| 61 | 3 | } | |||||||||||||||||
| 62 | 3 | ▶ | |||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 63 | 3 | method _build_ext { | |||||||||||||||||
| 64 | ($self->_split_name)[2]; | ||||||||||||||||||
| 65 | } | ||||||||||||||||||
| 66 | 16 | ▶ | |||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
_trigger_ext: called CC=3 SCAR=11.2
Branch: 2 branches
| |||||||||||||||||||
| 67 | 1 | ||||||||||||||||||
| 68 | method with_ext( $ext ) { | ||||||||||||||||||
| 69 | $ext =~ s/ \A [.] //xms; | ||||||||||||||||||
| 70 | 16 | ▶ | my ($f, $d, $e) = $self->_split_name; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BUILD: called CC=3 SCAR=11.2
Branch: 2 branches
| |||||||||||||||||||
| 71 | 35 | return $self->name if $e eq $ext; | |||||||||||||||||
| 72 | return canonpath( $d . $f . $ext ); | ||||||||||||||||||
| 73 | } | ||||||||||||||||||
| 74 | 0 | ▶ | |||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
_read_file: not called CC=3 SCAR=21.6
Branch: 1 branch
| |||||||||||||||||||
| 75 | 0 | method _trigger_ext( $old_ext ) { | |||||||||||||||||
| 76 | 0 | ▶ | $self->name( $self->with_ext( $self->ext ) ); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 77 | } | ||||||||||||||||||
| 78 | 0 | ||||||||||||||||||
| 79 | method BUILD( $args ) { | ||||||||||||||||||
| 80 | 0 | $self->{_original_name} = $self->name; | |||||||||||||||||
| 81 | } | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | method _read_file { | ||||||||||||||||||
| 84 | 16 | ▶ | my $fname = $self->_original_name; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
update_notes: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 85 | 3 | open my $fh, '<', $fname or die "can't open $fname for reading: $!"; | |||||||||||||||||
| 86 | |||||||||||||||||||
| 87 | binmode $fh, ':raw'; | ||||||||||||||||||
| 88 | 16 | ||||||||||||||||||
| 89 | my $content = do { local $/; <$fh> }; | ||||||||||||||||||
| 90 | } | ||||||||||||||||||
| 91 | |||||||||||||||||||
| 92 | |||||||||||||||||||
| 93 | method update_notes( %notes ) { | ||||||||||||||||||
| 94 | @{ $self->notes }{ keys %notes } = values %notes; | ||||||||||||||||||
| 95 | } | ||||||||||||||||||
| 96 | |||||||||||||||||||
| 97 | 1; | ||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||