| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 29 | 181 | ▶ | my $obj = $self->load($store_file) or die "Failed to retrieve $path"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 50 | 15 | ▶ | mkdir $store_dir or croak "Failed to make repository dir $store_dir"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 41 | ▶ | my $creator = $self->can('user') ? $self->user : $proto->user or croak "Username not specified"; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$fil and -d $path
MC/DC50%1/2
$fil and -d $path
$fil
-d $path
Truth table66%2/3
A and B
A= $filB= -d $path
| |||||||||||||||||||||||||||||
| 67 | 163 | $dir = catdir($dir,$fil); | |||||||||||||||||||||||||||
| 68 | 163 | $fil = ''; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 426 | ▶ | if (ref $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | my ($hvol,$hdir) = splitpath($self->{home}); | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | croak "Wrong volume in attempt to access store for $path" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||