blib/lib/HTML/T5/Message.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 4 / 4 Conditioncond 88.8% 8 / 9 MC/DCmcdc 80.0% 4 / 5 Subroutinesub 100% 10 / 10 Podpod 100% 7 / 7 totaltotal 97.2% 70 / 72 CC 7 SCAR 9.7
CC
7
Cov
98%
as_string
5.0
new
3.0
BEGIN
1.0
CRAP 2.6
« blib/lib/Test/HTML/T5.pm ↑ Summary T5.xs »
1 package HTML::T5::Message;
2  
3 25 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 HTML::T5::Message - Message object for the Tidy functionality
10  
11 =head1 EXPORTS
12  
13 None. It's all object-based.
14  
15 =head1 METHODS
16  
17 Almost everything is an accessor.
18  
19 =head2 new( $file, $line, $column, $text )
20  
21 Create an object. It's not very exciting.
22  
23 C<$file> can be C<undef> or an empty string, in which case it will not appear in messages.
24  
25 =cut
26  
27 179 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
28 179 my $class = shift;
29  
30 179 my $file = shift;
31 179 my $type = shift;
32 179 ▶ my $line = shift || 0;
Condition100%2/2
shift() || 0
l!l
16217
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
33 179 ▶ my $column = shift || 0;
Condition100%2/2
shift() || 0
l!l
16217
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
34 179 my $text = shift;
35  
36 # Add an element that says what tag caused the error (B, TR, etc)
37 # so that we can match 'em up down the road.
38 179 my $self = {
39 _file => $file,
40 _type => $type,
41 _line => $line,
42 _column => $column,
43 _text => $text,
44 };
45  
46 179 bless $self, $class;
47  
48 179 return $self;
49 }
50  
51 =head2 as_string()
52  
53 Returns a nicely-formatted string for printing out to stdout or some similar user thing.
54  
55 =cut
56  
57 61 ▶sub as_string {
Subroutine as_string: called CC=5 SCAR=16.1
Pod documented
58 61 my $self = shift;
59  
60 61 my %strings = (
61 1 => 'Info',
62 2 => 'Warning',
63 3 => 'Error',
64 );
65  
66 61 my $msg = $strings{$self->type} . ': ' . $self->text;
67  
68 61 ▶ if ( $self->line && $self->column ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->line and $self->column) 59 2 61
Condition66%2/3
$self->line and $self->column
!ll&&!rl&&r
2059
MC/DC50%1/2
$self->line and $self->column
$self->line $self->column
Truth table66%2/3
A and B
A= $self->lineB= $self->column
ABresult
0X0
100
111
69 59 $msg = sprintf( '(%d:%d) %s', $self->line, $self->column, $msg );
70 }
71  
72 61 ▶ my $file = $self->file // '';
Condition100%2/2
$self->file // ""
l!l
3328
MC/DC100%1/1
$self->file // ""
$self->file
Truth table100%2/2
A
A= $self->file
Aresult
11
00
73 61 ▶ if ( $file ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file ne "") 24 37 61
74 24 $msg = "$file $msg";
75 }
76  
77 61 return $msg;
78 }
79  
80 =head2 file()
81  
82 Returns the filename of the error, as set by the caller.
83  
84 =head2 type()
85  
86 Returns the type of the error. This will either be C<TIDY_ERROR>,
87 or C<TIDY_WARNING>.
88  
89 =head2 line()
90  
91 Returns the line number of the error, or 0 if there isn't an applicable
92 line number.
93  
94 =head2 column()
95  
96 Returns the column number, or 0 if there isn't an applicable column
97 number.
98  
99 =head2 text()
100  
101 Returns the text of the message. This does not include a type string,
102 like "Info: ".
103  
104 =cut
105  
106 65 ▶sub file { my $self = shift; return $self->{_file} }
Subroutine file: called CC=1 SCAR=0.0
Pod documented
107 116 ▶sub type { my $self = shift; return $self->{_type} }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
108 124 ▶sub line { my $self = shift; return $self->{_line} }
Subroutine line: called CC=1 SCAR=0.0
Pod documented
109 122 ▶sub column { my $self = shift; return $self->{_column} }
Subroutine column: called CC=1 SCAR=0.0
Pod documented
110 92 ▶sub text { my $self = shift; return $self->{_text} }
Subroutine text: called CC=1 SCAR=0.0
Pod documented
111  
112  
113 =head1 COPYRIGHT & LICENSE
114  
115 Copyright 2005-2018 Andy Lester.
116  
117 This program is free software; you can redistribute it and/or modify
118 it under the terms of the Artistic License v2.0.
119  
120 =head1 AUTHOR
121  
122 Andy Lester, C<< <andy@petdance.com> >>
123  
124 =cut
125  
126 25 1; # happy
« blib/lib/Test/HTML/T5.pm ↑ Summary T5.xs »