File Coverage

blib/lib/POE/Component/MessageQueue/Statistics/Publish/YAML.pm
Criterion Covered Total %
statement 18 31 58.0
branch 0 6 0.0
condition n/a
subroutine 6 8 75.0
pod 2 2 100.0
total 26 47 55.3


line stmt bran cond sub pod time code
1             # $Id$
2             #
3             # Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>
4             # All rights reserved.
5             #
6             # This program is free software: you can redistribute it and/or modify
7             # it under the terms of the GNU General Public License as published by
8             # the Free Software Foundation, either version 3 of the License, or
9             # (at your option) any later version.
10             #
11             # This program is distributed in the hope that it will be useful,
12             # but WITHOUT ANY WARRANTY; without even the implied warranty of
13             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14             # GNU General Public License for more details.
15             #
16             # You should have received a copy of the GNU General Public License
17             # along with this program. If not, see <http://www.gnu.org/licenses/>.
18              
19             package POE::Component::MessageQueue::Statistics::Publish::YAML;
20 1     1   946 use strict;
  1         4  
  1         25  
21 1     1   4 use warnings;
  1         3  
  1         23  
22 1     1   6 use base qw(POE::Component::MessageQueue::Statistics::Publish);
  1         2  
  1         371  
23 1     1   401 use Best [ qw(YAML::Syck YAML) ], qw(Dump);
  1         1340  
  1         6  
24 1     1   1123 use File::Temp;
  1         6343  
  1         64  
25 1     1   388 use File::Copy qw(move);
  1         1649  
  1         177  
26              
27             sub publish_file
28             {
29 0     0 1   my ($self, $filename) = @_;
30              
31             # Be friendly to people who might be reading the file
32 0           my $fh = File::Temp->new(UNLINK => 0);
33 0           my %h = %{ $self->{statistics}->{statistics} };
  0            
34 0           eval {
35 0           $fh->print( Dump( { %h, generated => scalar localtime } ) );
36 0           $fh->flush;
37 0 0         move($fh->filename, $filename) or die "Failed to rename $fh to $filename: $!";
38             };
39 0 0         if (my $e = $@) {
40 0 0         $fh->unlink_on_destroy( 1 ) if $fh;
41 0           die $e;
42             }
43             }
44              
45             sub publish_handle
46             {
47 0     0 1   my ($self, $handle) = @_;
48 0           $handle->print( Dump( $self->{statistics}->{statistics} ) );
49             }
50              
51             1;
52              
53             __END__
54              
55             =head1 NAME
56              
57             POE::Component::MessageQueue::Statistics::Publish::YAML - Publish Statistics In YAML Format
58              
59             =head1 SYNOPSIS
60              
61             use POE::Component::MessageQueue::Statistics;
62             use POE::Component::MessageQueue::Statistics::Publish::YAML;
63              
64             # This is initialized elsewhere
65             my $stats = POE::Component::MessageQueue::Statistics->new();
66              
67             my $publish = POE::Component::MessageQueue::Statistics::Publish::YAML->new(
68             output => \*STDOUT,
69             statistics => $stats
70             );
71             $publish->publish();
72              
73             =head1 DESCRIPTION
74              
75             This module dumps the statistics information in YAML format
76              
77             =head1 SEE ALSO
78              
79             L<POE::Component::MessageQueue::Statistics>,
80             L<POE::Component::MessageQueue::Statistics::Publish>
81              
82             =head1 AUTHOR
83              
84             Daisuke Maki E<lt>daisuke@endeworks.jpE<gt>
85              
86             =cut