VCS/Cvs.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 91 CC 4 SCAR 15.1
CC
4
Cov
0%
_split_log
12.0
_read_pipe
6.0
_boiler_plate_info
2.0
CRAP 4.5
1 package VCS::Cvs;
2  
3 use strict;
4 use vars qw($VERSION);
5 use Cwd qw(cwd);
6 use File::Spec::Functions qw(splitpath);
7 use VCS::Cvs::Dir;
8 use VCS::Cvs::File;
9 use VCS::Cvs::Version;
10  
11 $VERSION = '0.06';
12  
13 my $LOG_CMD = "cvs log";
14  
15 my %LOG_CACHE;
16  
17 sub _boiler_plate_info {
18 my ($self, $what) = @_;
19 my ($header, $log) = $self->_split_log($self->{VERSION});
20 my $rev_info = $self->_parse_log_rev($log);
21 $rev_info->{$what};
22 }
23  
24 sub _split_log {
25 my ($self, $version) = @_;
26 my $log_text;
27 my $cache_id = $self->url;
28 unless (defined($log_text = $LOG_CACHE{$cache_id})) {
29  
30 my $cwd = cwd();
31 my($volume, $path, $file) = splitpath($self->path);
32 chdir $path;
33  
34 my $cmd =
35 $LOG_CMD .
36 " " . $file . " 2>/dev/null |";
37 #warn "cmd: $cmd\n";
38 $LOG_CACHE{$cache_id} = $log_text = $self->_read_pipe($cmd);
39  
40 chdir $cwd;
41 }
42 my @sections = split /\n[=\-]+\n/, $log_text;
43 @sections = ($sections[0], grep { /^revision $version(?:\s+locked by.*?)?\n/ } @sections)
44 if $version;
45 #map { print "SEC: $_\n" } @sections;
46 @sections;
47 }
48  
49 sub _parse_log_rev {
50 my ($self, $text) = @_;
51 my ($rev_line, $blurb, @reason) = split /\n/, $text;
52 my %info = map {
53 split /:\s+/
54 } split /;\s*/, $blurb;
55 my ($junk, $rev) = split /\s+/, $rev_line;
56 $info{'revision'} = $rev;
57 $info{'reason'} = \@reason;
58 #print "REASON: @reason\n";
59 #map { print "$_ => $info{$_}\n" } keys %info;
60 \%info;
61 }
62  
63 sub _parse_log_header {
64 my ($self, $text) = @_;
65 $text =~ s#(description:.*)##s;
66 my $desc = join "\n ", split /\n/, $1;
67 $text .= $desc;
68 my @parts = $text =~ /^(\S.*?)(?=^\S|\Z)/gms;
69 chomp @parts;
70 #map { print "PART: $_\n" } @parts;
71 my %info = map {
72 split /:\s*/, $_, 2
73 } @parts;
74 #map { print "$_ => $info{$_}\n" } keys %info;
75 \%info;
76 }
77  
78 sub _read_pipe {
79 my ($self, $cmd) = @_;
80 local *PIPE;
81 open PIPE, $cmd;
82 local $/ = undef;
83 my $contents = <PIPE>;
84 close PIPE;
85 $contents = '' unless defined $contents;
86 return $contents;
87 }
88  
89 1;
90  
91  
92 __END__