Metrics/Parser.pm

filter: Statementstmt 30.7% 12 / 39 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 3 / 5 Podpod 0.0% 0 / 2 totaltotal 23.0% 15 / 65 CC 9 SCAR 35.0
CC
9
Cov
21%
parse
56.0
new
12.0
BEGIN
1.0
CRAP 33.2
« Metrics.pm ↑ Summary Metrics/Graph.pm »
1 package CVS::Metrics::Parser;
2
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 1 our $VERSION = '0.18';
7
8 1 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 1 our %cvs_log;
11
12 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
13 0 my $proto = shift;
14 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
15 0 my $self = {};
16 0 bless($self, $class);
17
18 0 my $grammar = q{
19 File: EOL rcs working head branch lock access symbolic keyword total selected Description
20 {
21 $CVS::Metrics::Parser::cvs_log{$item[3]} = {
22 'rcs file' => $item[2],
23 # 'working file' => $item[3],
24 'head' => $item[4],
25 # 'branch' => $item[5],
26 # 'locks' => $item[6],
27 # 'access list' => $item[7],
28 'symbolic names' => $item[8],
29 # 'keyword subtitution' => $item[9],
30 'total revisions' => $item[10],
31 # 'selected revisions' => $item[11],
32 'description' => $item[12]
33 };
34 }
35
36 rcs: 'RCS file:' /[^,]+/ ',v' EOL
37 { $item[2]; }
38
39 working: 'Working file:' /(.*)/ EOL
40 { $item[2]; }
41
42 head: 'head:' /(.*)/ EOL
43 { $item[2]; }
44
45 branch: 'branch:' /(.*)/ EOL
46 { $item[2]; }
47
48 lock: 'locks:' /(.*)/ EOL
49 { $item[2]; }
50
51 access: 'access list:' /(.*)/ EOL
52 { $item[2]; }
53
54 symbolic: 'symbolic names:' EOL Tag(s?)
55 {
56 my @list;
57 foreach (@{$item[3]}) {
58 push @list, @{$_};
59 }
60 my %hash = @list;
61 \%hash;
62 }
63
64 Tag: /[0-9A-Za-z_\-\.]+/ ':' /[0-9\.]+/ EOL
65 {
66 [ $item[1], $item[3] ];
67 }
68
69 keyword: 'keyword substitution:' /(.*)/ EOL
70 { $item[2]; }
71
72 total: 'total revisions:' /[0-9]+/ SEMICOL
73 { $item[2]; }
74
75 selected: 'selected revisions:' /[0-9]+/ EOL
76 { $item[2]; }
77
78 Description: 'description:' EOL imported(?) Revision(s)
79 {
80 my @list;
81 foreach (@{$item[4]}) {
82 push @list, @{$_};
83 }
84 my %hash = @list;
85 \%hash;
86 }
87
88 imported: /(Imported|\.)/ /(.*)/ EOL
89
90 Revision: /[-]+\n/ id date author state line(?) EOL branches(?) EOL(s?) message(s?)
91 {
92 [
93 $item[2],
94 {
95 'date' => $item[3],
96 'author' => $item[4],
97 'state' => $item[5],
98 # 'line_add' => ${$item[6]}[0],
99 # 'line_del' => ${$item[6]}[1],
100 'branches' => ${$item[8]}[0],
101 'message' => join "\n", @{$item[10]},
102 }
103 ];
104 }
105
106 id: 'revision' /[0-9\.]+/ EOL
107 { $item[2]; }
108
109 date: 'date:' /[^;]+/ SEMICOL
110 { $item[2]; }
111
112 author: 'author:' /[^;]+/ SEMICOL
113 { $item[2]; }
114
115 state: 'state:' /[^;]+/ SEMICOL
116 { $item[2]; }
117
118 line: 'lines:' /[-+]?[0-9]+/ /[-+]?[0-9]+/
119 { [ $item[2] , $item[3] ]; }
120
121 branches: 'branches:' Rev(s) EOL
122 { $item[2]; }
123
124 Rev: /[0-9\.]+/ SEMICOL
125 { $item[1]; }
126
127 message: /([^\-].*)|([-]+[^\-\n].*)/ EOL
128 { $item[1] || $item[2]; }
129
130 SEMICOL: ';'
131
132 EOL: /\n/
133 };
134 0 $Parse::RecDescent::skip = '[ \t]*';
135 0 $self->{parser} = Parse::RecDescent->new($grammar);
136 0 ▶ return undef unless (defined $self->{parser});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"parser"} 0 0 0
137 0 return $self;
138 }
139
140 0 ▶sub parse {
Subroutine parse: not called CC=7 SCAR=40.3
Pod undocumented
141 0 my $self = shift;
142 0 my ($cvs_logfile) = @_;
143
144 0 %cvs_log = ();
145 0 $Parse::RecDescent::skip = '[ \t]*';
146 # $::RD_TRACE = 1;
147 0 my $text;
148 0 ▶ open my $IN, $cvs_logfile
Branch: 1 branch
BranchTrueFalseTotal
open my $IN, $cvs_logfile or die "can't open CVS output ($!).\n" 0 0 0
149 or die "can't open CVS output ($!).\n";
150 0 ▶ while (<$IN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $IN)) 0 0 0
151 0 $text = $_;
152 0 ▶ last unless (/^\?/);
Branch: 1 branch
BranchTrueFalseTotal
unless /^\?/ 0 0 0
153 }
154 0 ▶ while (<$IN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $IN)) 0 0 0
155 0 ▶ if (/^[=]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[=]+$/) { } 0 0 0
156 0 ▶ unless (defined $self->{parser}->File($text)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"parser"}->File($text)) 0 0 0
157 0 warn "Not matched\n$text\n";
158 }
159 0 $text = '';
160 }
161 else {
162 0 $text .= $_;
163 }
164 }
165 0 close $IN;
166 0 my $metric = \%cvs_log;
167 0 return bless $metric, 'CVS::Metrics';
168 }
169
170 1 1;
171
« Metrics.pm ↑ Summary Metrics/Graph.pm »