189 lines
4.6 KiB
Perl
189 lines
4.6 KiB
Perl
=head1 NAME
|
|
|
|
Dam::Debug
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
API for handling error, warning, information and debug messages.
|
|
|
|
=head1 FUNCTIONS
|
|
|
|
=cut
|
|
|
|
use strict;
|
|
use warnings;
|
|
use utf8;
|
|
|
|
package Dam::Debug;
|
|
|
|
use Exporter qw(import);
|
|
our @EXPORT = qw(
|
|
report_error report_warning report_info
|
|
debug_error debug_info debug
|
|
);
|
|
|
|
use Date::Calc qw(Now);
|
|
|
|
use Dam::Util;
|
|
use Dam::Var;
|
|
|
|
|
|
|
|
=head2 report_error(@message)
|
|
|
|
Push an error message to display in report execution.
|
|
|
|
=head3 Arguments:
|
|
|
|
- B<@message> (must): Error message formed by one or more strings.
|
|
|
|
=cut
|
|
|
|
sub report_error {
|
|
my $error = strval(@_);
|
|
my $REPORT_ERROR = RESERVED('REF_REPORT_ERROR');
|
|
push(@$REPORT_ERROR, $error) if !is_empty($error);
|
|
}
|
|
|
|
|
|
|
|
=head2 report_warning(@message)
|
|
|
|
Push a warning message to display in report execution.
|
|
|
|
=head3 Arguments:
|
|
|
|
- B<@message> (must): Warning message formed by one or more strings.
|
|
|
|
=cut
|
|
|
|
sub report_warning {
|
|
my $warning = strval(@_);
|
|
my $REPORT_WARNING = RESERVED('REF_REPORT_WARNING');
|
|
push(@$REPORT_WARNING, $warning) if !is_empty($warning);
|
|
}
|
|
|
|
|
|
|
|
=head2 report_info(@message)
|
|
|
|
Push an information message to display in report execution.
|
|
|
|
=head3 Arguments:
|
|
|
|
- B<@message> (must): Information message formed by one or more strings.
|
|
|
|
=cut
|
|
|
|
sub report_info {
|
|
my $info = strval(@_);
|
|
my $REPORT_INFO = RESERVED('REF_REPORT_INFO');
|
|
push(@$REPORT_INFO, $info) if !is_empty($info);
|
|
}
|
|
|
|
|
|
|
|
=head2 debug_error(@message)
|
|
|
|
Prepares a message with current time to display (according to
|
|
B<CONFIG('DEBUG_MODE')>) with all code debug messages sorted at the beginning of
|
|
the current report.
|
|
|
|
=head3 Arguments:
|
|
|
|
- B<@message>: Error message formed by one or more strings.
|
|
|
|
=cut
|
|
|
|
sub debug_error {
|
|
my $DEBUG_INFO = RESERVED('REF_DEBUG_INFO');
|
|
push(@$DEBUG_INFO, strval('[', sprintf("%02d:%02d:%02d", Now()), '] <strong style="color: red;">ERROR!</strong> <samp style="color: navy;">', @_, '</samp>')) if CONFIG('DEBUG_MODE');
|
|
}
|
|
|
|
|
|
|
|
=head2 debug_info($title, @message)
|
|
|
|
Prepare a message with current time, a short title and data of the function and
|
|
the call files, to show (according to B<CONFIG('DEBUG_MODE')>) with all code
|
|
debugging messages sorted at the beginning of the current report.
|
|
|
|
=head3 Arguments:
|
|
|
|
- B<$title> (must): Short title to show.
|
|
- B<@message>: Message formed by one or more strings.
|
|
|
|
=cut
|
|
|
|
sub debug_info {
|
|
my ($title, @message) = @_;
|
|
|
|
if (CONFIG('DEBUG_MODE')) {
|
|
my ($p0, $filename0, $line0) = caller(1);
|
|
$filename0 = substr($filename0, 3);
|
|
my ($p1, $filename1, $line1, $subroutine1) = caller(2);
|
|
$filename1 = substr($filename1, 3);
|
|
my $DEBUG_INFO = RESERVED('REF_DEBUG_INFO');
|
|
push(@$DEBUG_INFO, strval(
|
|
'[', sprintf("%02d:%02d:%02d", Now()), '] <strong>', $title, '</strong>: ',
|
|
'<code>', $filename0, '</code> línea ', $line0, ' (<code>', substr($subroutine1, 9), '</code>)',
|
|
index($filename1, 'CGI/Application.pm') == -1 ? strval(', desde <code>', $filename1, '</code> línea ', $line1) : '',
|
|
'.<br />', @message
|
|
));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
=head2 debug($title, @message)
|
|
|
|
Prepare a message with current time and a short title to display (according to
|
|
B<CONFIG('DEBUG_MODE')>) with all code debugging messages sorted at the
|
|
beginning of the current report.
|
|
|
|
=head3 Arguments:
|
|
|
|
- B<$title> (must): Short title to show.
|
|
- B<@message>: Message formed by one or more strings.
|
|
|
|
=cut
|
|
|
|
sub debug {
|
|
my ($title, @message) = @_;
|
|
my $DEBUG_INFO = RESERVED('REF_DEBUG_INFO');
|
|
push(@$DEBUG_INFO, strval('[', sprintf("%02d:%02d:%02d", Now()), '] <strong>', $title, '</strong>: ', @message)) if CONFIG('DEBUG_MODE');
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
=head1 AUTHOR
|
|
|
|
Manuel Cillero C<< <manuel@cillero.es> >>
|
|
|
|
=head1 COPYRIGHT
|
|
|
|
The MIT License (MIT)
|
|
|
|
Copyright (c) 2004-2020 Manuel Cillero. All rights reserved.
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
|
|
=cut
|