Log-Channel
view release on metacpan or search on metacpan
=cut
sub new {
my $proto = shift;
my $class = ref ($proto) || $proto;
if (!$Configuration) {
$Configuration = new Log::Channel::Config;
}
my $package = (caller)[0];
if ($package ne "main") {
unshift @_, $package;
}
if (!$Channel{$package}) {
# make sure channel exists for the entire package
$class->_make($package);
}
return $class->_make(@_);
}
=item B<_carp>
This is the function that is used to supersede the regular Carp::carp
whenever Carp is commandeered on a module. Note that we still use
Carp::shortmess to generate the actual text, so that if Carp verbose mode
is specified, the full verbose text will go to the log channel.
=cut
sub _carp {
my $topic = (caller)[0];
my $channel = $Channel{$topic}->{channel};
$channel = Log::Channel->_make($topic) unless $channel;
$channel->(Carp::shortmess @_);
}
=item B<_croak>
Substitute for Carp::croak. Note that in this case the message will
be output to two places - the channel, and STDERR (or whatever die() does).
=cut
sub _croak {
my $topic = (caller)[0];
my $channel = $Channel{$topic}->{channel};
$channel = Log::Channel->_make($topic) unless $channel;
$channel->(Carp::shortmess @_);
die Carp::shortmess @_;
}
=item B<decorate>
Exports a logging subroutine into the calling package's namespace.
Does the same thing as
sub mylog { $channel->(@_) }
=cut
sub export {
my ($channel, $subname) = @_;
my $package = (caller)[0];
no strict 'refs';
*{"$package\::$subname"} = sub { $channel->(@_) };
}
1;
=back
( run in 1.188 second using v1.01-cache-2.11-cpan-1e74a51a04c )