blib/lib/VCS/Lite/Store.pm

filter: Statementstmt 82.7% 48 / 58 Branchbran 58.3% 14 / 24 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 90.0% 9 / 10 Podpod 100% 5 / 5 totaltotal 77.4% 79 / 102 CC 14 SCAR 18.2
CC
14
Cov
75%
store_path
13.8
create
5.1
retrieve
3.0
CRAP 6.2
« blib/lib/VCS/Lite/Element.pm ↑ Summary blib/lib/VCS/Lite/Shell.pm »
1 package VCS::Lite::Store;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 our $VERSION = '0.11';
7  
8 #----------------------------------------------------------------------------
9  
10 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use File::Spec::Functions qw(:ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 our $hidden_repos_dir = '.VCSLite';
15 8 ▶$hidden_repos_dir = '_VCSLITE' if $^O =~ /vms/i;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /vms/i 0 8 8
16  
17 #----------------------------------------------------------------------------
18  
19 sub new {
20 0 ▶ my ($pkg, %par) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
21 0 bless \%par,$pkg;
22 }
23  
24 sub retrieve {
25 248 ▶ my ($self, $path) = @_;
Subroutine retrieve: called CC=3 SCAR=11.0
Pod documented
26  
27 248 my $store_file = $self->store_path($path);
28 248 ▶ return unless -e $store_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $store_file 67 181 248
29 181 ▶ my $obj = $self->load($store_file) or die "Failed to retrieve $path";
Branch: 1 branch
BranchTrueFalseTotal
my $obj = $self->load($store_file) or die "Failed to retrieve $path" 0 181 181
30 181 $obj->{store} = $self;
31 181 $obj;
32 }
33  
34 sub retrieve_or_create {
35 121 ▶ my ($self, $proto) = @_;
Subroutine retrieve_or_create: called CC=2 SCAR=6.9
Pod documented
36  
37 121 my $path = $proto->path;
38  
39 121 ▶ $self->retrieve($path) || $self->create($proto);
Branch: 1 branch
BranchTrueFalseTotal
$self->retrieve($path) or $self->create($proto) 41 80 121
40 }
41  
42 sub create {
43 41 ▶ my ($self, $proto) = @_;
Subroutine create: called CC=5 SCAR=16.3
Pod documented
44  
45 41 my $path = $proto->path;
46  
47 41 my ($store_dir, $store_file) = $self->store_path($path);
48  
49 41 ▶ if (!-d $store_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $store_dir) 15 26 41
50 15 ▶ mkdir $store_dir or croak "Failed to make repository dir $store_dir";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $store_dir or croak("Failed to make repository dir $store_dir") 0 15 15
51 }
52  
53 41 ▶ my $creator = $self->can('user') ? $self->user : $proto->user or croak "Username not specified";
Branch: 2 branches
BranchTrueFalseTotal
my $creator = $self->can("user") ? $self->user : $proto->user or croak("Username not specified") 0 41 41
$self->can('user') ? : 0 41 41
54  
55 41 @{$proto}{qw/store creator created/} = ($self,$creator,localtime->datetime);
56 41 my $class = ref $proto;
57 41 $proto->_mumble("Creating $class $path");
58 41 $proto->save($store_file);
59 41 $proto;
60 }
61  
62 sub store_path {
63 426 ▶ my ($self,$path,$ext) = @_;
Subroutine store_path: called CC=7 SCAR=26.3
Pod documented
64  
65 426 my ($vol,$dir,$fil) = splitpath(rel2abs($path));
66 426 ▶ if ($fil && -d $path) { # Because of the way splitpath works on Unix
Branch: 1 branch
BranchTrueFalseTotal
if ($fil and -d $path) 163 263 426
Condition66%2/3
$fil and -d $path
!ll&&!rl&&r
0263163
MC/DC50%1/2
$fil and -d $path
$fil -d $path
Truth table66%2/3
A and B
A= $filB= -d $path
ABresult
0X0
100
111
67 163 $dir = catdir($dir,$fil);
68 163 $fil = '';
69 }
70  
71 426 ▶ if (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 426 426
72 0 my ($hvol,$hdir) = splitpath($self->{home});
73 0 ▶ croak "Wrong volume in attempt to access store for $path"
Branch: 1 branch
BranchTrueFalseTotal
if $hvol ne $vol 0 0 0
74 if $hvol ne $vol;
75 0 my @dir = splitdir($dir);
76 0 for (splitdir($hdir)) {
77 0 my $dd = shift @dir;
78 0 ▶ croak "Outside directory tree: $path" if $dd ne $_;
Branch: 1 branch
BranchTrueFalseTotal
if $dd ne $_ 0 0 0
79 }
80 0 ($vol,my $rdir) = splitpath($self->{root});
81 0 $dir = catdir($rdir,@dir);
82 } else {
83 426 $dir = catdir($dir,$hidden_repos_dir);
84 }
85  
86 426 ($dir, catpath($vol, $dir, $self->repos_name($fil,$ext)));
87 }
88  
89 8 1;
90  
91 __END__
« blib/lib/VCS/Lite/Element.pm ↑ Summary blib/lib/VCS/Lite/Shell.pm »