| 1 | package RackMan::File; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use File::Basename; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use File::Path; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | ▶ | use Path::Class; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 3 | ▶ | use RackMan; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | 3 | has name => ( | |||||||||||
| 12 | is => "rw", | ||||||||||||
| 13 | isa => "Str", | ||||||||||||
| 14 | ); | ||||||||||||
| 15 | |||||||||||||
| 16 | 3 | has path => ( | |||||||||||
| 17 | is => "rw", | ||||||||||||
| 18 | isa => "Str", | ||||||||||||
| 19 | ); | ||||||||||||
| 20 | |||||||||||||
| 21 | 3 | has content => ( | |||||||||||
| 22 | is => "rw", | ||||||||||||
| 23 | isa => "Str", | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | |||||||||||||
| 26 | |||||||||||||
| 27 | # | ||||||||||||
| 28 | # fullpath() | ||||||||||||
| 29 | # -------- | ||||||||||||
| 30 | 0 | ▶ | sub fullpath { | ||||||||||
|
Subroutine
fullpath: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 31 | 0 | my $self = shift; | |||||||||||
| 32 | 0 | my $file = file(grep length, $self->path, $self->name); | |||||||||||
| 33 | 0 | return "$file" | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | |||||||||||||
| 37 | # | ||||||||||||
| 38 | # add_content() | ||||||||||||
| 39 | # ----------- | ||||||||||||
| 40 | 3 | ▶ | sub add_content { | ||||||||||
|
Subroutine
add_content: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 41 | 3 | my $self = shift; | |||||||||||
| 42 | 3 | ▶ | $self->content( join "", $self->content || "", @_ ); | ||||||||||
|
Condition100%2/2
$self->content || ''
MC/DC100%1/1
$self->content || ''
$self->content
Truth table100%2/2
A
A= $self->content
| |||||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | |||||||||||||
| 46 | # | ||||||||||||
| 47 | # read() | ||||||||||||
| 48 | # ---- | ||||||||||||
| 49 | 0 | ▶ | sub read { | ||||||||||
|
Subroutine
read: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 50 | 0 | my $self = shift; | |||||||||||
| 51 | 0 | my $file = file($self->path, $self->name); | |||||||||||
| 52 | 0 | ▶ | my $fh = $file->open("<") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | or RackMan->error("can't read '$file': $!"); | ||||||||||||
| 54 | { | ||||||||||||
| 55 | 0 | local $/; # slurp mode | |||||||||||
| 56 | 0 | $self->content($fh->getline); | |||||||||||
| 57 | } | ||||||||||||
| 58 | 0 | $fh->close; | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | |||||||||||||
| 62 | # | ||||||||||||
| 63 | # write() | ||||||||||||
| 64 | # ----- | ||||||||||||
| 65 | 1 | ▶ | sub write { | ||||||||||
|
Subroutine
write: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 66 | 1 | my $self = shift; | |||||||||||
| 67 | 1 | my $file = file($self->path, $self->name); | |||||||||||
| 68 | 1 | mkpath dirname("$file"); | |||||||||||
| 69 | 1 | ▶ | my $fh = $file->open(">") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | or RackMan->error("can't write '$file': $!"); | ||||||||||||
| 71 | 1 | $fh->print($self->content); | |||||||||||
| 72 | 1 | $fh->close; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | |||||||||||||
| 76 | 3 | __PACKAGE__->meta->make_immutable | |||||||||||
| 77 | |||||||||||||
| 78 | __END__ | ||||||||||||