| 1 | 1 | require 5.006; | |||||||||||||||||||||||||||
| 2 | package Mail::Box::MH::Resource; | ||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Mail::Reporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use vars ('$VERSION', @ISA); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | $VERSION = 0.06; | |||||||||||||||||||||||||||
| 8 | 1 | @ISA = 'Mail::Reporter'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | local($_, $/, %ENV); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | my $curdir = File::Spec->catfile(File::Spec->curdir(), 'foo'); | |||||||||||||||||||||||||||
| 13 | 1 | $curdir =~s/\bfoo$//; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | sub new{ | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=35.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 1 | shift; | |||||||||||||||||||||||||||
| 17 | 1 | my $self = bless {}; | |||||||||||||||||||||||||||
| 18 | 1 | $self->SUPER::init(); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | unless( $self->{_file} = shift ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if( exists($ENV{MH}) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | $self->{_file} = File::Spec->file_name_is_absolute($ENV{MH}) ? | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $ENV{MH} : File::Spec->catfile(cwd(), $ENV{MH}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $self->{_file} ||= File::Spec->catfile($ENV{HOME}, '.mh_profile'); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_file"} ||= "File::Spec"->catfile($ENV{"HOME"}, ".mh_profile")
MC/DC0%0/2
$self->{"_file"} ||= "File::Spec"->catfile($ENV{"HOME"}, ".mh_profile")
$self->{"_file"}
"File::Spec"->catfile($ENV{"HOME"}, ".mh_profile")
Truth table0%0/3
A ||= B
A= $self->{"_file"}B= "File::Spec"->catfile($ENV{"HOME"}, ".mh_profile")
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | unless( File::Spec->file_name_is_absolute($self->{_file}) || | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
"File::Spec"->file_name_is_absolute($self->{"_file"}) or $self->{"_file"} =~ /^\Q$curdir\E/
MC/DC0%0/2
"File::Spec"->file_name_is_absolute($self->{"_file"}) or $self->{"_file"} =~ /^\Q$curdir\E/
"File::Spec"->file_name_is_absolute($self->{"_file"})
$self->{"_file"} =~ /^\Q$curdir\E/
Truth table33%1/3
A or B
A= "File::Spec"->file_name_is_absolute($self->{"_file"})B= $self->{"_file"} =~ /^\Q$curdir\E/
| |||||||||||||||||||||||||||||
| 28 | $self->{_file} =~ m%^\Q$curdir\E% ){ | ||||||||||||||||||||||||||||
| 29 | 0 | my $profile = Mail::Box::MH::Resource->new(); | |||||||||||||||||||||||||||
| 30 | 0 | my $path = $profile->get('Path'); | |||||||||||||||||||||||||||
| 31 | $path = File::Spec->file_name_is_absolute($path) ? $path : | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | File::Spec->catdir($ENV{HOME}, $path); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | $self->{_file} = File::Spec->catfile($path, $self->{_file}); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | if( -e $self->{_file} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | if( open(my $profile, $self->{_file}) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | while( <$profile> ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 2 | chomp; | |||||||||||||||||||||||||||
| 40 | 2 | ▶ | next unless defined($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | #MH doesn't strip out leading whitespace, so this is okay | ||||||||||||||||||||||||||||
| 42 | 2 | my @F = split(/:\s*/, $_ ,2); | |||||||||||||||||||||||||||
| 43 | 2 | $self->{_profile}->{$F[0]} = $F[1]; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 1 | close($profile); | |||||||||||||||||||||||||||
| 46 | 1 | $self->log(PROGRESS=>"Resource file F<$self->{_file}> opened for read."); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | else{ | ||||||||||||||||||||||||||||
| 49 | 0 | $self->log(ERROR=>"Resource file F<$self->{_file}> could not be opened for read: $!"); | |||||||||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else{ | ||||||||||||||||||||||||||||
| 54 | 0 | $self->log(NOTICE=>"Resource file F<$self->{_file}> does not exist, it will be created on close()"); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | return $self; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub get{ | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | return @{shift->{_profile}}{@_}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub set{ | ||||||||||||||||||||||||||
|
Subroutine
set: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 65 | 0 | my %hash = @_; | |||||||||||||||||||||||||||
| 66 | 0 | $self->{_profile}->{$_} = $hash{$_} for keys %hash; | |||||||||||||||||||||||||||
| 67 | #XXX Should this actually only get touched if any keys are *modified*? | ||||||||||||||||||||||||||||
| 68 | 0 | $self->{_modified} = 1; | |||||||||||||||||||||||||||
| 69 | }; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub close{ | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | if( open(my $profile, '>', $self->{_file}) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | print $profile "$_: $self->{_profile}->{$_}$/" for keys %{$self->{_profile}}; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | close($profile) && ($self->{_modified} = 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | $self->log(PROGRESS=>"Resource file F<$self->{_file}> synced."); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | else{ | ||||||||||||||||||||||||||||
| 79 | 0 | $self->log(ERROR=>"Resource file F<$self->{_file}> could not be open for write: $!"); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | }; | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub enum{ | ||||||||||||||||||||||||||
|
Subroutine
enum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | keys %{shift->{_profile}}; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | sub DESTROY{ | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||
| 88 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | 1 | ▶ | return unless $self->{_modified}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||
| 91 | $self->log( | ||||||||||||||||||||||||||||
| 92 | WARNING=>"Resource file F<$self->{_file}> modifications | ||||||||||||||||||||||||||||
| 93 | were destroyed, save changes by calling close() first:\n". | ||||||||||||||||||||||||||||
| 94 | 0 | Data::Dumper->Dump([$self->{_profile}])); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | 1; | |||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||