| Module-Checkstyle documentation | Contained in the Module-Checkstyle distribution. |
Module::Checkstyle::Problem - Represents a checkstyle violation
use Module::Checkstyle::Problem;
my $problem = Module::Checkstyle::Problem->new('warn',
q(bad variable name '$java'),
40,
'my_script.pl');
Constructs a new Module::Checkstyle::Problem object. $severity should be
any of error or warn but others may be specified. $message should be
a description of the violated check. $line may either be a scalar or a
reference to an array where it will use the first element as line. $file should
be the path to the file that violates the check.
Returns the severity of the problem.
Returns the description of the problem.
Returns the line where the problem was found.
Returns the file that caused the problem.
Returns a stringified message combining severity, message, line and file if they are present.
| Module-Checkstyle documentation | Contained in the Module-Checkstyle distribution. |
package Module::Checkstyle::Problem; use strict; use warnings; use overload q{""} => \&as_string; sub new { my ($class, $severity, $message, $line, $file) = @_; $class = ref $class || $class; if (defined $line && ref $line) { if (UNIVERSAL::isa($line, 'PPI::Element')) { $line = $line->location(); } # Assume this is comming from a PPI::Element->location(); if (ref $line eq 'ARRAY') { $line = $line->[0]; } } my $self = bless [ $severity, $message, $line, $file ], $class; return $self; } sub as_string { my $self = shift; my $str = q{}; if (defined $self->[0]) { $str .= uc("[$self->[0]] "); } if (defined $self->[1]) { $str .= $self->[1]; } if (defined $self->[2]) { $str .= " at line $self->[2]"; } if (defined $self->[3]) { $str .= " in $self->[3]"; } return $str; } sub get_severity { return $_[0]->[0]; } sub get_message { return $_[0]->[1]; } sub get_line { return $_[0]->[2]; } sub get_file { return $_[0]->[3]; } 1; __END__