lib/File/Information/Lock.pm

filter: Statementstmt 48.1% 13 / 27 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 100% 3 / 3 totaltotal 43.4% 20 / 46 CC 5 SCAR 25.9
CC
5
Cov
37%
new
30.0
instance
2.0
parent
2.0
CRAP 13.3
« blib/lib/File/Information/Lock.pm ↑ Summary blib/lib/File/Information/VerifyBase.pm »
1 # Copyright (c) 2024-2025 Philipp Schafft <lion@cpan.org>
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: generic module for extracting information from filesystems
6  
7  
8 package File::Information::Lock;
9  
10 3 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 our $VERSION = v0.16;
17  
18  
19 sub new {
20 0 ▶ my ($pkg, %opts) = @_;
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
21 0 my $self = bless \%opts, $pkg;
22  
23 0 ▶ $self->{instance} = $self->{parent}->instance unless defined $self->{instance};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"instance"} 0 0 0
24  
25 0 ▶ croak 'No instance is given' unless defined $self->{instance};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"instance"} 0 0 0
26 0 ▶ croak 'No parent is given' unless defined $self->{parent};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"parent"} 0 0 0
27 0 ▶ croak 'No on_unlock is given' unless defined $self->{on_unlock};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"on_unlock"} 0 0 0
28  
29 0 return $self;
30 }
31  
32  
33  
34 sub instance {
35 0 ▶ my ($self) = @_;
Subroutine instance: not called CC=1 SCAR=6.9
Pod documented
36 0 return $self->{instance};
37 }
38  
39  
40 sub parent {
41 0 ▶ my ($self) = @_;
Subroutine parent: not called CC=1 SCAR=6.9
Pod documented
42 0 return $self->{parent};
43 }
44  
45 # ----------------
46  
47 sub DESTROY {
48 0 ▶ my ($self) = @_;
Subroutine DESTROY: not called CC=1 SCAR=6.9
49 0 my $func = $self->{on_unlock};
50 0 $self->parent->$func($self);
51 }
52  
53 3 1;
54  
55 __END__
56  
57 =pod
58  
59 =encoding UTF-8
60  
61 =head1 NAME
62  
63 File::Information::Lock - generic module for extracting information from filesystems
64  
65 =head1 VERSION
66  
67 version v0.16
68  
69 =head1 SYNOPSIS
70  
71 use File::Information;
72  
73 my File::Information::Lock $lock = $obj->lock;
74  
75 This package is used to represent locks on resources and objects.
76  
77 The lock is hold until the last reference to the object is gone.
78  
79 =head1 METHODS
80  
81 =head2 new
82  
83 my File::Information::Lock $lock = File::Information::Lock->new([ instance => $instance, ] parent => $parent, on_unlock => \&unlock_sub);
84  
85 Returns a new lock object. Requires an instance (L<File::Information>), a parent object (what is locked), and an unlock function.
86 If no instance is given C<$parent-E<gt>instance> is called to obtain one.
87  
88 Once this lock is gone the unlock function is called. It is normally a private method of the object that is locked.
89 The unlock function is responsible of handling the case with multiple lock objects being alive at the same time. So any unlock function must check
90 if all locks are gone before performing an actual unlock. The unlock function is called on C<$parent> and passing the lock as first argument.
91  
92 =head2 instance
93  
94 my File::Information $instance = $lock->instance;
95  
96 Returns the instance that was used to create this object.
97  
98 =head2 parent
99  
100 my $parent = $lock->parent;
101  
102 Returns the parent that was used to create this object.
103  
104 =head1 AUTHOR
105  
106 Philipp Schafft <lion@cpan.org>
107  
108 =head1 COPYRIGHT AND LICENSE
109  
110 This software is Copyright (c) 2024-2025 by Philipp Schafft <lion@cpan.org>.
111  
112 This is free software, licensed under:
113  
114 The Artistic License 2.0 (GPL Compatible)
115  
116 =cut
« blib/lib/File/Information/Lock.pm ↑ Summary blib/lib/File/Information/VerifyBase.pm »