Basset
view release on metacpan or search on metacpan
lib/Basset/Logger.pm view on Meta::CPAN
$logger->close();
Create a logger object, then log data to it, then close it when you're done. Easy as pie.
Works beautifully in conjunction with Basset::NotificationCenter.
You will B<need> to put a types entry into your conf file for
logger=Basset::Logger
(or whatever center you're using)
=cut
$VERSION = '1.01';
use Basset::Object;
our @ISA = Basset::Object->pkg_for_type('object');
use strict;
use warnings;
=pod
=head1 ATTRIBUTES
=over
=item handle
The place you log to. Either a string (which will be opened in append mode) or a globref.
$logger->handle('/path/to/log.log');
open (LOG, ">>/path/to/log.log");
$logger->handle(\*LOG);
=cut
__PACKAGE__->add_attr(['handle', '_isa_file_accessor']);
=pod
=begin btest handle
my $o = __PACKAGE__->new();
$test->ok($o, "Got object for handle");
$test->is(scalar($o->handle($o)), undef, "Cannot set handle to unknown reference");
$test->is($o->errcode, "BL-03", "proper error code");
local $@ = undef;
eval "use File::Temp";
my $file_temp_exists = $@ ? 0 : 1;
if ($file_temp_exists) {
my $temp = File::Temp->new;
my $name = $temp->filename;
$test->is(ref($o->handle($name)), 'GLOB', "created glob");
open (my $glob, $name);
$test->is($o->handle($glob), $glob, "set glob");
chmod 000, $name;
$test->is(scalar($o->handle($name)), undef, "could not set handle to unwritable file");
$test->is($o->errcode, "BL-01", "proper error code");
}
=end btest
=cut
=pod
=item closed
=cut
__PACKAGE__->add_attr('closed');
=pod
=begin btest closed
{
my $o = __PACKAGE__->new();
$test->ok($o, "Got object");
$test->is(scalar(__PACKAGE__->closed), undef, "could not call object method as class method");
$test->is(__PACKAGE__->errcode, "BO-08", "proper error code");
$test->is(scalar($o->closed), 0, 'closed is 0 by default');
$test->is($o->closed('abc'), 'abc', 'set closed to abc');
$test->is($o->closed(), 'abc', 'read value of closed - abc');
my $h = {};
$test->ok($h, 'got hashref');
$test->is($o->closed($h), $h, 'set closed to hashref');
$test->is($o->closed(), $h, 'read value of closed - hashref');
my $a = [];
$test->ok($a, 'got arrayref');
$test->is($o->closed($a), $a, 'set closed to arrayref');
$test->is($o->closed(), $a, 'read value of closed - arrayref');
}
my $o = __PACKAGE__->new();
$test->ok($o, "got object");
$test->is($o->close, 1, "closing non-existent handle is fine");
$test->is($o->closed, 0, "handle remains open");
local $@ = undef;
eval "use File::Temp";
my $file_temp_exists = $@ ? 0 : 1;
if ($file_temp_exists) {
my $temp = File::Temp->new;
my $name = $temp->filename;
$test->is(ref($o->handle($name)), 'GLOB', "created glob");
$test->is($o->closed, 0, "file handle is open");
$test->is($o->close, 1, "closed file handle");
$test->is($o->closed, 1, "filehandle is closed");
}
=end btest
=cut
( run in 0.807 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )