blib/lib/VCS/LibCVS/RepositoryFileOrDirectory.pm

filter: Statementstmt 23.6% 13 / 55 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 40.0% 4 / 10 Podpod 83.3% 5 / 6 totaltotal 18.4% 22 / 119 CC 18 SCAR 33.2
CC
18
Cov
14%
get_name
56.0
find
30.0
new
30.0
CRAP 27.6
« blib/lib/VCS/LibCVS/Client.pm ↑ Summary blib/lib/VCS/LibCVS/IgnoreChecker.pm »
1 #
2 # Copyright (c) 2003,2004,2005 Alexander Taler (dissent@0--0.org)
3 #
4 # All rights reserved. This program is free software; you can redistribute it
5 # and/or modify it under the same terms as Perl itself.
6 #
7  
8 package VCS::LibCVS::RepositoryFileOrDirectory;
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use File::Spec::Unix;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 VCS::LibCVS::RepositoryFileOrDirectory - An object in the repository.
18  
19 =head1 SYNOPSIS
20  
21 =head1 DESCRIPTION
22  
23 Represents a CVS object in the repository, either a file or a directory. You
24 shouldn't use this directly, instead you should use RepositoryFile and
25 RepositoryDirectory which inherit from it.
26  
27 =cut
28  
29 ###############################################################################
30 # Class constants
31 ###############################################################################
32  
33 1 ▶use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/RepositoryFileOrDirectory.pm,v 1.14 2005/10/10 12:52:11 dissent Exp $ ';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 ###############################################################################
36 # Class variables
37 ###############################################################################
38  
39 ###############################################################################
40 # Private variables
41 ###############################################################################
42  
43 # $self->{Repository} The VCS::LibCVS::Repository in which the object lives.
44 #
45 # $self->{FileSpec} Path of $self in the repository filesystem
46 # Canonized with File::Spec::Unix, and relative to the
47 # repository root. Repositories always use UNIX Filespecs
48  
49 ###############################################################################
50 # Class routines
51 ###############################################################################
52  
53 =head1 CLASS ROUTINES
54  
55 =head2 B<find()>
56  
57 $rep_obj = VCS::LibCVS::RepositoryFileOrDirectory->find($repository, $name)
58  
59 =over 4
60  
61 =item return type: subclass of VCS::LibCVS::RepositoryFileOrDirectory
62  
63 =item argument 1 type: VCS::LibCVS::Repository
64  
65 =item argument 2 type: string scalar
66  
67 The path of a file or directory within the repository.
68  
69 =back
70  
71 It will return either a VCS::LibCVS::RepositoryDirectory or
72 VCS::LibCVS::RepositoryFile object, depending on what the second argument
73 names.
74  
75 =cut
76  
77 0 ▶sub find {
Subroutine find: not called CC=5 SCAR=34.0
Pod documented
78 0 my $class = shift;
79  
80 # First see if it's already in the repository cache
81 0 ▶ if ($VCS::LibCVS::Cache_RepositoryFileOrDirectory) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VCS::LibCVS::Cache_RepositoryFileOrDirectory) 0 0 0
82 0 my ($repo, $path) = @_;
83 0 my $cache = $repo->{RepositoryFileOrDirectoryCache};
84 0 ▶ return $cache->{$path} if $cache->{$path};
Branch: 1 branch
BranchTrueFalseTotal
if $cache->{$path} 0 0 0
85 }
86  
87 0 my $file_or_dir;
88 # Try to load it as a file, if an exception is thrown, then it's a directory.
89 0 eval { $file_or_dir = VCS::LibCVS::RepositoryFile->new(@_); };
90 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
91 0 ▶ if ($@ !~ /^.* is a directory./) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@ =~ /^.* is a directory./) 0 0 0
92 0 confess($@);
93 }
94 0 $file_or_dir = VCS::LibCVS::RepositoryDirectory->new(@_);
95 }
96  
97 0 return $file_or_dir;
98 }
99  
100 # This constructor is private, there's no reason for anything except the
101 # subclasses to call it.
102  
103 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
104 0 my $class = shift;
105 0 my ($repo, $path) = @_;
106  
107 # If the path is absolute, make it relative to the repository
108 0 ▶ if (File::Spec::Unix->file_name_is_absolute($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("File::Spec::Unix"->file_name_is_absolute($path)) 0 0 0
109 0 my $base = $repo->get_root()->get_dir();
110 0 $path = File::Spec::Unix->abs2rel( $path, $base );
111 }
112  
113 # Clean up the path. See issue 47.
114 0 $path = File::Spec::Unix->canonpath($path);
115  
116 # Look in the repo's cache for this file
117 0 my $cache = $repo->{RepositoryFileOrDirectoryCache};
118 return $cache->{$path}
119 0 ▶ if $VCS::LibCVS::Cache_RepositoryFileOrDirectory && $cache->{$path};
Branch: 1 branch
BranchTrueFalseTotal
if $VCS::LibCVS::Cache_RepositoryFileOrDirectory and $cache->{$path} 0 0 0
Condition0%0/3
$VCS::LibCVS::Cache_RepositoryFileOrDirectory and $cache->{$path}
!ll&&!rl&&r
000
MC/DC0%0/2
$VCS::LibCVS::Cache_RepositoryFileOrDirectory and $cache->{$path}
$VCS::LibCVS::Cache_RepositoryFileOrDirectory $cache->{$path}
Truth table0%0/3
A and B
A= $VCS::LibCVS::Cache_RepositoryFileOrDirectoryB= $cache->{$path}
ABresult
0X0
100
111
120  
121 0 my $that = bless {}, $class;
122 0 $that->{Repository} = $repo;
123 0 $that->{FileSpec} = $path;
124  
125 # Cache if appropriate
126 0 ▶ $cache->{$path} = $that if $VCS::LibCVS::Cache_RepositoryFileOrDirectory;
Branch: 1 branch
BranchTrueFalseTotal
if $VCS::LibCVS::Cache_RepositoryFileOrDirectory 0 0 0
127  
128 0 return $that;
129 }
130  
131 ###############################################################################
132 # Instance routines
133 ###############################################################################
134  
135 =head1 INSTANCE ROUTINES
136  
137 =head2 B<get_name()>
138  
139 $name = $r_obj->get_name({abs => 1})
140  
141 =over 4
142  
143 =item return type: scalar string
144  
145 =item argument 1 type: hash ref of options
146  
147 All options default to false.
148  
149 $opts->{abs} False: Don't return absolute filename
150 $opts->{no_dir} False: Include directory names
151 $opts->{no_base} False: Include the filename within the directory
152  
153 =back
154  
155 Returns the filename of the object with the repository, formatted according to
156 the options.
157  
158 =cut
159  
160 0 ▶sub get_name {
Subroutine get_name: not called CC=7 SCAR=40.3
Pod documented
161 0 my $self = shift;
162 0 ▶ my $opts = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
163  
164 0 my $abs = $self->{Repository}->get_root()->get_dir();
165 0 my ($vol, $dir, $base) = File::Spec::Unix->splitpath($self->{FileSpec});
166  
167 my $path = File::Spec::Unix->catdir($opts->{abs} ? "$abs" : (),
168 ($opts->{no_dir} || !$dir) ? () : "$dir",
169 0 ▶ $opts->{no_base} ? () : "$base");
Branch: 3 branches
BranchTrueFalseTotal
$opts->{'abs'} ? : 0 0 0
$opts->{'no_dir'} || !$dir ? : 0 0 0
$opts->{'no_base'} ? : 0 0 0
Condition0%0/3
$opts->{"no_dir"} or not $dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"no_dir"} or not $dir
$opts->{"no_dir"} not $dir
Truth table0%0/3
A or not(B)
A= $opts->{"no_dir"}B= not $dir
ABresult
1X1
011
000
170 # If there's no $dir, then it's the current dir, so return that
171 0 ▶ $path ||= File::Spec::Unix->curdir();
Condition0%0/3
$path ||= "File::Spec::Unix"->curdir
l!l&&r!l&&!r
000
MC/DC0%0/2
$path ||= "File::Spec::Unix"->curdir
$path "File::Spec::Unix"->curdir
Truth table0%0/3
A ||= B
A= $pathB= "File::Spec::Unix"->curdir
ABresult
1X1
011
000
172 0 return $path;
173 }
174  
175 =head2 B<get_repository()>
176  
177 $rep_obj->get_repository()
178  
179 =over 4
180  
181 =item return type: VCS::LibCVS::Repository
182  
183 =back
184  
185 Returns the repository in which this object lives.
186  
187 =cut
188  
189 0 ▶sub get_repository {
Subroutine get_repository: not called CC=1 SCAR=6.9
Pod documented
190 0 my $self = shift;
191 0 return $self->{Repository};
192 }
193  
194 =head2 B<get_directory_of()>
195  
196 $r_dir = $r_obj->get_directory_of()
197  
198 =over 4
199  
200 =item return type: VCS::LibCVS::RepositoryDirectory
201  
202 =back
203  
204 Returns the repository directory in which the object lives.
205  
206 For a top level relative repository directory (one with no / in the name), the
207 parent directory returned will be ".". For "." an exception will be thrown.
208  
209 =cut
210  
211 0 ▶sub get_directory_of {
Subroutine get_directory_of: not called CC=3 SCAR=24.8
Pod documented
212 0 my $self = shift;
213  
214 0 ▶ confess (". has no parent directory") if ($self->{FileSpec} eq ".");
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"FileSpec"} eq "." 0 0 0
215  
216 # totally screws up if there is a ".." in there. See issue 47.
217 0 ▶ my $dir = ($self->get_name({no_base => 1})) || ".";
Condition0%0/2
$self->get_name({'no_base', 1}) || '.'
l!l
00
MC/DC0%0/1
$self->get_name({'no_base', 1}) || '.'
$self->get_name({'no_base', 1})
Truth table0%0/2
A
A= $self->get_name({'no_base', 1})
Aresult
11
00
218 0 return VCS::LibCVS::RepositoryDirectory->new($self->{Repository}, $dir);
219 }
220  
221 =head2 B<equals()>
222  
223 if ($ford1->equals($ford2)) {
224  
225 =over 4
226  
227 =item return type: boolean
228  
229 =item argument 1 type: VCS::LibCVS::RepositoryFileOrDirectory
230  
231 =back
232  
233 Returns true if this and the other "f or d" represent the same thing in the
234 repository.
235  
236 =cut
237  
238 0 ▶sub equals {
Subroutine equals: not called CC=2 SCAR=17.9
Pod documented
239 0 my $self = shift;
240 0 my $other = shift;
241  
242 return ( $self->{Repository}->equals($other->{Repository})
243 0 ▶ && ($self->{FileSpec} eq $other->{FileSpec}));
Condition0%0/3
$self->{'Repository'}->equals($other->{'Repository'}) && $self->{'FileSpec'} eq $other->{'FileSpec'}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'Repository'}->equals($other->{'Repository'}) && $self->{'FileSpec'} eq $other->{'FileSpec'}
$self->{'Repository'}->equals($other->{'Repository'}) $self->{'FileSpec'} eq $other->{'FileSpec'}
Truth table0%0/3
A && B
A= $self->{'Repository'}->equals($other->{'Repository'})B= $self->{'FileSpec'} eq $other->{'FileSpec'}
ABresult
0X0
100
111
244 }
245  
246 ###############################################################################
247 # Private routines
248 ###############################################################################
249  
250  
251 =head1 SEE ALSO
252  
253 VCS::LibCVS
254  
255 =cut
256  
257 1 1;
« blib/lib/VCS/LibCVS/Client.pm ↑ Summary blib/lib/VCS/LibCVS/IgnoreChecker.pm »