|
Revision 19333, 0.8 kB
(checked in by daisuke, 5 years ago)
|
|
とりあえずログ取ったりできるようになった
|
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | # $Id$ |
|---|
| 2 | |
|---|
| 3 | package Morris::Plugin::Channel::Log::File; |
|---|
| 4 | use Moose; |
|---|
| 5 | use MooseX::Types::Path::Class qw(Dir File); |
|---|
| 6 | use File::Spec; |
|---|
| 7 | |
|---|
| 8 | with 'Morris::Plugin::Channel::Log::Handle'; |
|---|
| 9 | |
|---|
| 10 | has 'directory' => ( |
|---|
| 11 | is => 'rw', |
|---|
| 12 | isa => Dir, |
|---|
| 13 | required => 1, |
|---|
| 14 | coerce => 1, |
|---|
| 15 | builder => 'build_dir', |
|---|
| 16 | lazy => 1 |
|---|
| 17 | ); |
|---|
| 18 | |
|---|
| 19 | has 'file' => ( |
|---|
| 20 | is => 'rw', |
|---|
| 21 | isa => File, |
|---|
| 22 | required => 1, |
|---|
| 23 | coerce => 1, |
|---|
| 24 | builder => 'build_file', |
|---|
| 25 | lazy => 1 |
|---|
| 26 | ); |
|---|
| 27 | |
|---|
| 28 | __PACKAGE__->meta->make_immutable; |
|---|
| 29 | |
|---|
| 30 | no Moose; |
|---|
| 31 | |
|---|
| 32 | sub build_dir { |
|---|
| 33 | return Path::Class::Dir->new(File::Spec->tmpdir); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | sub build_file { |
|---|
| 37 | my $self = shift; |
|---|
| 38 | my $file = $self->directory->file( |
|---|
| 39 | sprintf( '%s.log', $self->channel ) ); |
|---|
| 40 | return $file; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | sub build_handle { |
|---|
| 44 | my $self = shift; |
|---|
| 45 | my $fh = $self->file->open('a'); |
|---|
| 46 | $fh->autoflush(1); |
|---|
| 47 | return $fh; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | 1; |
|---|