| 1 | # Copyright 2004-2026, Paul Johnson (paul@pjcj.net) | ||
| 2 | |||
| 3 | # This software is free. It is licensed under the same terms as Perl itself. | ||
| 4 | |||
| 5 | # The latest version of this software should be available from my homepage: | ||
| 6 | # https://pjcj.net | ||
| 7 | |||
| 8 | package Devel::Cover::Annotation::Random; | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | |||
| 13 | our $VERSION = '1.52'; # VERSION | ||
| 14 | |||
| 15 | use Getopt::Long; | ||
| 16 | |||
| 17 | sub new { | ||
| 18 | my $class = shift; | ||
| 19 | bless {@_}, $class | ||
| 20 | } | ||
| 21 | |||
| 22 | sub get_options { | ||
| 23 | my ($self, $opt) = @_; | ||
| 24 | $self->{count} = 1; | ||
| 25 | die "Bad option" unless GetOptions( | ||
| 26 | $self, qw( | ||
| 27 | count=s | ||
| 28 | ) | ||
| 29 | ); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub count { | ||
| 33 | my $self = shift; | ||
| 34 | $self->{count} | ||
| 35 | } | ||
| 36 | |||
| 37 | sub header { | ||
| 38 | my $self = shift; | ||
| 39 | my ($annotation) = @_; | ||
| 40 | "rnd$annotation" | ||
| 41 | } | ||
| 42 | |||
| 43 | sub width { | ||
| 44 | my $self = shift; | ||
| 45 | my ($annotation) = @_; | ||
| 46 | length $self->header($annotation) | ||
| 47 | } | ||
| 48 | |||
| 49 | sub text { | ||
| 50 | my $self = shift; | ||
| 51 | my ($file, $line, $annotation) = @_; | ||
| 52 | return "" unless $line; | ||
| 53 | $self->{annotation}{$file}[$line][$annotation] = int rand 10 | ||
| 54 | unless defined $self->{annotation}{$file}[$line][$annotation]; | ||
| 55 | $self->{annotation}{$file}[$line][$annotation] | ||
| 56 | } | ||
| 57 | |||
| 58 | sub error { | ||
| 59 | my $self = shift; | ||
| 60 | my ($file, $line, $annotation) = @_; | ||
| 61 | !$self->text($file, $line, $annotation) | ||
| 62 | } | ||
| 63 | |||
| 64 | sub class { | ||
| 65 | my $self = shift; | ||
| 66 | my ($file, $line, $annotation) = @_; | ||
| 67 | return "" unless $line; | ||
| 68 | "c" . int(($self->text($file, $line, $annotation) + 2) / 3) | ||
| 69 | } | ||
| 70 | |||
| 71 | 1 | ||
| 72 | |||
| 73 | __END__ |