| 1 | package Cantella::Store::UUID; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Class::MOP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Data::GUID; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use File::Copy qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Path::Class qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Cantella::Store::UUID::Util '_mkdirs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use MooseX::Types::Path::Class qw/Dir/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.003003'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | has nest_levels => ( | |||||||||||||||||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | has root_dir => ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | isa => Dir, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | required => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | has file_class => ( | ||||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | isa => 'ClassName', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | Class::MOP::load_class('Cantella::Store::UUID::File'); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return 'Cantella::Store::UUID::File'; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # File::Copy 2.10 introduced 'sub _eq' in lieu of a simple "$from eq $to" check | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # to enable checking of whether strings _or_ refs were identical. However, this | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # resulted in | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # Argument "...." isn't numeric in numeric eq (==) at /usr/share/perl/5.10/File/Copy.pm line 70. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # this hack will implement File::Copy 2.13's version of 'sub _eq' | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # 5.8.8 File::Copy 2.09 -- ok | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # 5.9.5 File::Copy 2.10 -- broken | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # 5.8.9 File::Copy 2.13 -- ok | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # 5.10.0 File::Copy 2.11 -- broken | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # 5.10.1 File::Copy 2.14 -- ok | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | if ($File::Copy::VERSION >= 2.10 && $File::Copy::VERSION <= 2.12) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$File::Copy::VERSION >= "2.1" and $File::Copy::VERSION <= "2.12"
MC/DC0%0/2
$File::Copy::VERSION >= "2.1" and $File::Copy::VERSION <= "2.12"
$File::Copy::VERSION >= "2.1"
$File::Copy::VERSION <= "2.12"
Truth table33%1/3
A and B
A= $File::Copy::VERSION >= "2.1"B= $File::Copy::VERSION <= "2.12"
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | Class::MOP::Package->initialize('File::Copy')->add_package_symbol('&_eq' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $Scalar_Util_loaded = eval q{ require Scalar::Util; require overload; 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 57 | my ($from, $to) = map { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $Scalar_Util_loaded && Scalar::Util::blessed($_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$Scalar_Util_loaded and builtin::blessed($_) and overload::Method($_, "\"\"")
$Scalar_Util_loaded and builtin::blessed($_)
MC/DC0%0/3
$Scalar_Util_loaded and builtin::blessed($_) and overload::Method($_, "\"\"")
$Scalar_Util_loaded
builtin::blessed($_)
overload::Method($_, "\"\"")
Truth table0%0/4
A and B and C
A= $Scalar_Util_loadedB= builtin::blessed($_)C= overload::Method($_, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | && overload::Method($_, q{""}) | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ? "$_" | ||||||||||||||||||||||||||||||||||||||||||
| 61 | : $_ | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } (@_); | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return '' if ( (ref $from) xor (ref $to) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
ref $from xor ref $to
MC/DC0%0/2
ref $from xor ref $to
ref $from
ref $to
Truth table0%0/4
A xor B
A= ref $fromB= ref $to
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return $from == $to if ref $from; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return $from eq $to; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub from_uuid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_uuid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ($self, $uuid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return $self->file_class->new( | |||||||||||||||||||||||||||||||||||||||||
| 72 | uuid => $uuid, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | dir => $self->_get_dir_for_uuid($uuid), | ||||||||||||||||||||||||||||||||||||||||||
| 74 | _document_store => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub new_uuid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_uuid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | Data::GUID->new; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub create_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_file: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my( $self, $source_file, $uuid, $metadata) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $source_file = Path::Class::file($source_file) unless blessed $source_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my %meta = %{ $metadata || {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$metadata || {}
MC/DC0%0/1
$metadata || {}
$metadata
Truth table0%0/2
A
A= $metadata
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $meta{original_name} = $source_file->basename; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $new_file = $self->from_uuid( $uuid ); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $new_file->metadata( \%meta ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return $new_file if File::Copy::copy($source_file, $new_file->path); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $new_path = $new_file->path; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | die("File copy from ${source_file} to ${new_path} failed: $!"); | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub deploy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $root = $self->root_dir; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | unless( -d $root || $root->mkpath ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $root or $root->mkpath
MC/DC0%0/2
-d $root or $root->mkpath
-d $root
$root->mkpath
Truth table0%0/3
A or B
A= -d $rootB= $root->mkpath
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | die("Failed to create ${root}"); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | _mkdirs($root, $self->nest_levels); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub _get_dir_for_uuid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_dir_for_uuid: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my ($self, $uuid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $uuid = Data::GUID->from_any_string($uuid) unless blessed $uuid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $target = $self->root_dir; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my @dirs = split('', uc(substr($uuid->as_hex, 2, $self->nest_levels))); | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return $target->subdir( @dirs ); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub grep_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
grep_files: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my($self, $test) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my @result; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my $callback = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return if $node->is_dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return unless $node->basename =~ /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $uuid; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $uuid = Data::GUID->from_string($node->basename); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | warn("Invalid object in file storage at: ${node}"); | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | push(@result, $uuid) if $test->( $self->from_uuid($uuid) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->root_dir->recurse(callback => $callback, depthfirst => 1, preorder => 0); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return @result; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub map_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_files: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my($self, $block) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my @result; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $callback = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return if $node->is_dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | return unless $node->basename =~ /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $uuid; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $uuid = Data::GUID->from_string($node->basename); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | warn("Invalid object in file storage at: ${node}"); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | push(@result, $block->( $self->from_uuid($uuid) )); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $self->root_dir->recurse(callback => $callback, depthfirst => 1, preorder => 0); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return @result; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | __END__; | ||||||||||||||||||||||||||||||||||||||||||