| 1 | package Net::DAV::LockManager::Simple; | ||||||||||
| 2 | |||||||||||
| 3 | 24 | ▶ | use Net::DAV::Lock; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 24 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 24 | our $VERSION = '1.304'; | |||||||||
| 8 | 24 | $VERSION = eval $VERSION; | |||||||||
| 9 | |||||||||||
| 10 | # | ||||||||||
| 11 | # This reference implementation of the lock management database interface | ||||||||||
| 12 | # provides an example of the simplest case of a pluggable lock management | ||||||||||
| 13 | # backend mechanism which can be swapped in for any other sort of | ||||||||||
| 14 | # implementation without concern for the operation of the lock manager | ||||||||||
| 15 | # itself. | ||||||||||
| 16 | # | ||||||||||
| 17 | |||||||||||
| 18 | # | ||||||||||
| 19 | # Create a new lock manager context. Optionally accepts an array | ||||||||||
| 20 | # containing a default set of locks. | ||||||||||
| 21 | # | ||||||||||
| 22 | sub new { | ||||||||||
| 23 | 143 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | |||||||||||
| 25 | 143 | return bless \@_, $class; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | # | ||||||||||
| 29 | # Stub method. Simply present to adhere to the lock management interface | ||||||||||
| 30 | # used within this package. | ||||||||||
| 31 | # | ||||||||||
| 32 | sub close { | ||||||||||
| 33 | 2 | ▶ | return; | ||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | # | ||||||||||
| 37 | # Given a normalized string representation of a resource path, return | ||||||||||
| 38 | # the first lock found. Otherwise, return undef if none is located. | ||||||||||
| 39 | # | ||||||||||
| 40 | sub get { | ||||||||||
| 41 | 563 | ▶ | my ($self, $path) = @_; | ||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 42 | |||||||||||
| 43 | 563 | foreach my $lock (@$self) { | |||||||||
| 44 | 301 | ▶ | if ($lock->path eq $path) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 115 | return $lock; | |||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 448 | return undef; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | # | ||||||||||
| 53 | # Given a path string, return all objects indexed whose path is a descendant | ||||||||||
| 54 | # of the one specified. | ||||||||||
| 55 | # | ||||||||||
| 56 | sub list_descendants { | ||||||||||
| 57 | 82 | ▶ | my ($self, $path) = @_; | ||||||||
|
Subroutine
list_descendants: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 58 | |||||||||||
| 59 | 82 | ▶ | return grep { $_->path ne '/' } @$self if $path eq '/'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 66 | return grep { index($_->path, "$path/") == 0 } @$self; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | # | ||||||||||
| 64 | # Given a Net::DAV::Lock object, replace any other locks whose | ||||||||||
| 65 | # path corresponds to that which is stored in the list. | ||||||||||
| 66 | # | ||||||||||
| 67 | sub update { | ||||||||||
| 68 | 5 | ▶ | my ($self, $lock) = @_; | ||||||||
|
Subroutine
update: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 69 | |||||||||||
| 70 | 5 | ▶ | for (my $i=0; $$self[$i]; $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 8 | ▶ | if ($$self[$i]->path eq $lock->path) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 5 | $$self[$i] = $lock; | |||||||||
| 73 | } | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 5 | return $lock; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | # | ||||||||||
| 80 | # Add the given lock object to the list. | ||||||||||
| 81 | # | ||||||||||
| 82 | sub add { | ||||||||||
| 83 | 86 | ▶ | my ($self, $lock) = @_; | ||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 84 | |||||||||||
| 85 | 86 | push @$self, $lock; | |||||||||
| 86 | |||||||||||
| 87 | 86 | return $lock; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | # | ||||||||||
| 91 | # Given a lock, the database record which contains the corresponding | ||||||||||
| 92 | # path will be removed. | ||||||||||
| 93 | # | ||||||||||
| 94 | sub remove { | ||||||||||
| 95 | 13 | ▶ | my ($self, $lock) = @_; | ||||||||
|
Subroutine
remove: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 96 | |||||||||||
| 97 | 13 | @{$self} = grep { $_->path ne $lock->path } @{$self}; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 24 | 1; | |||||||||
| 101 | |||||||||||
| 102 | __END__ | ||||||||||