Permalink
Browse files

Add svk annotation.

  • Loading branch information...
1 parent d3d54d3 commit a877f9676875d2a84f683d1a2d5c1f6745995288 @pjcj committed Apr 30, 2005
View
1 MANIFEST
@@ -8,6 +8,7 @@ create_gold
gcov2perl
lib/Devel/Cover.pm
lib/Devel/Cover/Annotation/Random.pm
+lib/Devel/Cover/Annotation/Svk.pm
lib/Devel/Cover/Branch.pm
lib/Devel/Cover/Condition.pm
lib/Devel/Cover/Condition_and_2.pm
View
20 lib/Devel/Cover/Annotation/Random.pm
@@ -48,30 +48,32 @@ sub width
{
my $self = shift;
my ($annotation) = @_;
- length $self->header($self->count)
+ length $self->header($annotation)
}
sub text
{
my $self = shift;
- my ($line, $annotation) = @_;
- $self->{annotation}{$line}{$annotation} = int rand 10
- unless exists $self->{annotation}{$line}{$annotation};
- $self->{annotation}{$line}{$annotation}
+ my ($file, $line, $annotation) = @_;
+ return "" unless $line;
+ $self->{annotation}{$file}[$line][$annotation] = int rand 10
+ unless defined $self->{annotation}{$file}[$line][$annotation];
+ $self->{annotation}{$file}[$line][$annotation]
}
sub error
{
my $self = shift;
- my ($line, $annotation) = @_;
- !$self->text($line, $annotation)
+ my ($file, $line, $annotation) = @_;
+ !$self->text($file, $line, $annotation)
}
sub class
{
my $self = shift;
- my ($line, $annotation) = @_;
- "c" . int($self->text($line, $annotation) / 3)
+ my ($file, $line, $annotation) = @_;
+ return "" unless $line;
+ "c" . int($self->text($file, $line, $annotation) / 3)
}
1
View
144 lib/Devel/Cover/Annotation/Svk.pm
@@ -0,0 +1,144 @@
+# Copyright 2005, Paul Johnson (pjcj@cpan.org)
+
+# This software is free. It is licensed under the same terms as Perl itself.
+
+# The latest version of this software should be available from my homepage:
+# http://www.pjcj.net
+
+package Devel::Cover::Annotation::Svk;
+
+use strict;
+use warnings;
+
+our $VERSION = "0.53";
+
+use Getopt::Long;
+
+sub new
+{
+ my $class = shift;
+ my $self =
+ {
+ annotations => [ qw( version author date ) ],
+ command => "svk annotate [[file]]",
+ @_
+ };
+ bless $self, $class
+}
+
+sub get_annotations
+{
+ my $self = shift;
+ my ($file) = @_;
+
+ return if exists $self->{_annotations}{$file};
+ my $a = $self->{_annotations}{$file} = [];
+
+ my $command = $self->{command};
+ $command =~ s/\[\[file\]\]/$file/g;
+ open my $c, "-|", $command or warn "Can't run $command: $!\n", return;
+ <$c>; <$c>; # ignore first two lines
+ while (<$c>)
+ {
+ my @a = /(\d+)\s*\(\s*(\S+)\s*(.*?)\):/;
+ push @$a, \@a;
+ }
+ close $c or warn "Failed running $command: $!\n"
+}
+
+sub get_options
+{
+ my ($self, $opt) = @_;
+ $self->{$_} = 1 for @{$self->{annotations}};
+ die "Bad option" unless
+ GetOptions($self,
+ qw(
+ author
+ command=s
+ date
+ version
+ ));
+}
+
+sub count
+{
+ my $self = shift;
+ $self->{author} + $self->{date} + $self->{version}
+}
+
+sub header
+{
+ my $self = shift;
+ my ($annotation) = @_;
+ $self->{annotations}[$annotation]
+}
+
+sub width
+{
+ my $self = shift;
+ my ($annotation) = @_;
+ (7, 10, 10)[$annotation]
+}
+
+sub text
+{
+ my $self = shift;
+ my ($file, $line, $annotation) = @_;
+ return "" unless $line;
+ $self->get_annotations($file);
+ $self->{_annotations}{$file}[$line - 1][$annotation]
+}
+
+sub error
+{
+ my $self = shift;
+ my ($file, $line, $annotation) = @_;
+ 0
+}
+
+sub class
+{
+ my $self = shift;
+ my ($file, $line, $annotation) = @_;
+ ""
+}
+
+1
+
+__END__
+
+=head1 NAME
+
+Devel::Cover::Annotation::Svk - Annotate with svk information
+
+=head1 SYNOPSIS
+
+ cover -report xxx -annotation svk
+
+=head1 DESCRIPTION
+
+Annotate coverage reports with svk annotation information.
+This module is designed to be called from the C<cover> program.
+
+=head1 SEE ALSO
+
+ Devel::Cover
+
+=head1 BUGS
+
+Huh?
+
+=head1 VERSION
+
+Version 0.53 - 17th April 2005
+
+=head1 LICENCE
+
+Copyright 2005, Paul Johnson (pjcj@cpan.org)
+
+This software is free. It is licensed under the same terms as Perl itself.
+
+The latest version of this software should be available from my homepage:
+http://www.pjcj.net
+
+=cut
View
6 lib/Devel/Cover/Report/Html_basic.pm
@@ -123,10 +123,10 @@ sub print_file
{
push @{$line{criteria}},
{
- text => $ann->text ($n, $a),
- class => $ann->class($n, $a),
+ text => $ann->text ($R{file}, $n, $a),
+ class => $ann->class($R{file}, $n, $a),
};
- $error ||= $ann->error($n, $a);
+ $error ||= $ann->error($R{file}, $n, $a);
}
}
for my $c (@{$R{showing}})
View
5 lib/Devel/Cover/Report/Text.pm
@@ -92,8 +92,9 @@ sub print_file
{
for my $a (0 .. $ann->count - 1)
{
- push @args, $ann->text($n, $a);
- $error ||= $ann->error($n, $a);
+ push @args,
+ substr $ann->text($file, $n, $a), 0, $ann->width($a);
+ $error ||= $ann->error($file, $n, $a);
}
}

0 comments on commit a877f96

Please sign in to comment.