File: Message.pm

package info (click to toggle)
libhtml-tidy5-perl 1.06-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 368 kB
  • sloc: perl: 1,853; makefile: 14
file content (126 lines) | stat: -rw-r--r-- 2,489 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package HTML::Tidy5::Message;

use 5.010001;
use warnings;
use strict;

=head1 NAME

HTML::Tidy5::Message - Message object for the Tidy functionality

=head1 EXPORTS

None.  It's all object-based.

=head1 METHODS

Almost everything is an accessor.

=head2 new( $file, $line, $column, $text )

Create an object.  It's not very exciting.

C<$file> can be C<undef> or an empty string, in which case it will not appear in messages.

=cut

sub new {
    my $class  = shift;

    my $file   = shift;
    my $type   = shift;
    my $line   = shift || 0;
    my $column = shift || 0;
    my $text   = shift;

    # Add an element that says what tag caused the error (B, TR, etc)
    # so that we can match 'em up down the road.
    my $self  = {
        _file   => $file,
        _type   => $type,
        _line   => $line,
        _column => $column,
        _text   => $text,
    };

    bless $self, $class;

    return $self;
}

=head2 as_string()

Returns a nicely-formatted string for printing out to stdout or some similar user thing.

=cut

sub as_string {
    my $self = shift;

    my %strings = (
        1 => 'Info',
        2 => 'Warning',
        3 => 'Error',
    );

    my $msg = $strings{$self->type} . ': ' . $self->text;

    if ( $self->line && $self->column ) {
        $msg = sprintf( '(%d:%d) %s', $self->line, $self->column, $msg );
    }

    my $file = $self->file // '';
    if ( $file ne '' ) {
        $msg = "$file $msg";
    }

    return $msg;
}

=head2 file()

Returns the filename of the error, as set by the caller.

=head2 type()

Returns the type of the error.  This will either be C<TIDY_ERROR>,
or C<TIDY_WARNING>.

=head2 line()

Returns the line number of the error, or 0 if there isn't an applicable
line number.

=head2 column()

Returns the column number, or 0 if there isn't an applicable column
number.

=head2 text()

Returns the text of the message.  This does not include a type string,
like "Info: ".

=cut

sub file    { my $self = shift; return $self->{_file} }
sub type    { my $self = shift; return $self->{_type} }
sub line    { my $self = shift; return $self->{_line} }
sub column  { my $self = shift; return $self->{_column} }
sub text    { my $self = shift; return $self->{_text} }


=head1 COPYRIGHT & LICENSE

Copyright 2005-2018 Andy Lester.

This program is free software; you can redistribute it and/or modify
it under the terms of the Artistic License v2.0.

=head1 AUTHOR

Andy Lester, C<< <andy@petdance.com> >>

=cut

1; # happy