| 1 | package DMOSS::Plugin::CommentLines; | ||||||||||||||||||||||||||||
| 2 | 1 | $DMOSS::Plugin::CommentLines::VERSION = '0.01_2'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: DMOSS number of comment lines plugin | ||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use parent qw/DMOSS::Plugin/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::Comments; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Slurp qw/read_file/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our @types = qw/_SOURCE/; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub name { 'Comment Lines' } | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 0 | my ($self, $dmoss, $file) = @_; | |||||||||||||||||||||||||||
| 17 | 0 | my $content = read_file $file->fullpath; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | my $snoop = File::Comments->new; | |||||||||||||||||||||||||||
| 20 | 0 | my $c = $snoop->comments($file->{fullpath}); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my $res = `wc -l $file->{fullpath}`; | |||||||||||||||||||||||||||
| 23 | 0 | my $total = 0; | |||||||||||||||||||||||||||
| 24 | 0 | ▶ | $total = $1 if ($res =~ m/(\d+)/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | my $comments = 0; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | $comments = @$c if $c; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | $dmoss->add_attr('comment_lines', {total=>$total, comments=>$comments}); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub reduce { | ||||||||||||||||||||||||||
|
Subroutine
reduce: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 0 | my ($self, $dmoss, @attrs) = @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my ($total, $comments) = (0, 0); | |||||||||||||||||||||||||||
| 35 | 0 | foreach my $a (@attrs) { | |||||||||||||||||||||||||||
| 36 | 0 | $total += $a->value->{total}; | |||||||||||||||||||||||||||
| 37 | 0 | $comments += $a->value->{comments}; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | $dmoss->add_attr('comment_lines', {total=>$total, comments=>$comments}); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub report { | ||||||||||||||||||||||||||
|
Subroutine
report: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 0 | my ($self, $dmoss, $attr) = @_; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | return unless ($attr->value and keys %{$attr->value}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attr->value and keys %{$attr->value;}
MC/DC0%0/2
$attr->value and keys %{$attr->value;}
$attr->value
keys %{$attr->value;}
Truth table0%0/3
A and B
A= $attr->valueB= keys %{$attr->value;}
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return unless $attr->value->{total}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($comments, $total) = ($attr->value->{comments}, $attr->value->{total}); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $p = $total ? int($comments/$total*100) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | return [ $attr->file->path, $comments, $total, "$p%" ]; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub report_headers { | ||||||||||||||||||||||||||
|
Subroutine
report_headers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my ($self, $dmoss) = @_; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | return [ '', 'Comment Lines', 'Total Lines', '% Comment Lines' ]; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub grade { | ||||||||||||||||||||||||||
|
Subroutine
grade: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $dmoss, $attr) = @_; | |||||||||||||||||||||||||||
| 61 | 0 | my ($comments, $total) = ($attr->value->{comments}, $attr->value->{total}); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return ($total ? ($comments/$total) : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | 1; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||