Crop

 view release on metacpan or  search on metacpan

lib/Crop/Error.pm  view on Meta::CPAN

=head1 SYNOPSIS

    use Crop::Error;
    # ...usage...

=head1 DESCRIPTION

Crop::Error provides error handling utilities for the Crop framework.

=head1 AUTHORS

Euvgenio (Core Developer)

Alex (Contributor)

=head1 COPYRIGHT AND LICENSE

Apache 2.0

=cut

use base qw/ Exporter /;

=begin nd
Class: Crop::Error
	Basic error-handle functions.
	
	This module redefines original perl function warn that has the 'true' return value, instead of
	the return value of this function. Be aware.
=cut

use v5.14;
use warnings;

use Time::Stamp -stamps => {dt_sep => ' ', ms => 1};

use Crop;

=begin nd
Constants: Error levels.

	Semantics is comming from the kernel error messages.

Constant: EMERG
	The system is broken absolutly.

	The most critically strong level.
	Unique sufficient choise for this state is to die silently and securitily is possible.

Constant: ALERT
	Fatal error of the main system.
	
	System can not do their work correctly so it must be stopped gracefully
	and terminate current request with respect to the user.

Constant: CRIT
	Critical resource error.
	
	May be temporary error. This state require sufficient reaction.

	Tipical causes are: unreachable third-party service or resource is busy, missing config file, etc.

Constant: ERR
	Business logic error.
	
	System is still in working state, but normal logic of request hadnler is broken. Reaction for
	this situation is defined by upper level code.

Constant: WARNING
	Default level.
	
	User input is wrong.

Constant: NOTICE
	Notable event that have not error semanitcs.

	For example, user has registered.

Constant: INFO
	User-defined event. It is not error.
=cut
use constant {
	EMERG   => 'EMERG',    # 0
	ALERT   => 'ALERT',    # 1
	CRIT    => 'CRIT',     # 2
	ERR     => 'ERR',      # 3
	WARNING => 'WARNING',  # 4
	NOTICE  => 'NOTICE',   # 5
	INFO    => 'INFO',     # 6
};

=begin nd
Variable: our @EXPORT
	By default is exported only basic <warn ( )> function.
	
Variable: our @EXPORT_OK
	Exported by order <all_right ( )> and <has_error ( )>.
=cut
our @EXPORT = qw/ &warn /;
our @EXPORT_OK = qw/ &all_right &has_error /;

=begin nd
Variable: my @Level
	Logging levels in order of decreasing fatality (strong errors first).

Variable: my %Level
	Maps LogLevel to the index number.
=cut
my @Level = (
	EMERG,
	ALERT,
	CRIT,
	ERR,
	WARNING,
	NOTICE,
	INFO,
);
my (%Level_ix, $i, $level);
$Level_ix{$level} = $i while ($i, $level) = each @Level;

=begin nd



( run in 0.591 second using v1.01-cache-2.11-cpan-39bf76dae61 )