File Coverage

blib/lib/Log/Dispatch/Spread.pm
Criterion Covered Total %
statement 19 21 90.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
1             package Log::Dispatch::Spread;
2              
3 1     1   40260 use strict;
  1         3  
  1         44  
4              
5 1     1   1421 use Log::Dispatch::Output;
  1         20241  
  1         30  
6 1     1   9 use base qw( Log::Dispatch::Output );
  1         9  
  1         65  
7              
8 1     1   20 use 5.008000;
  1         3  
  1         35  
9 1     1   5 use warnings;
  1         2  
  1         28  
10 1     1   5 no warnings 'uninitialized';
  1         2  
  1         43  
11 1     1   473 use Spread qw( :SP :ERROR :MESS );
  0            
  0            
12             use Carp;
13             use Params::Validate qw( :all );
14             use Sys::Hostname qw( hostname );
15              
16             our $VERSION = '0.9';
17              
18             use constant SPREAD_PRIV => 'jc-' . hostname();
19             use constant LOG_MSG_TYPE => 11;
20              
21             1;
22              
23             sub new {
24             my $proto = shift;
25             my $class = ref $proto || $proto;
26             my $self = bless {}, $class;
27              
28             my %p = @_;
29              
30             validate( @_, {
31             name => { type => SCALAR },
32             min_level => { type => SCALAR, default => 'DEBUG' },
33             max_level => { type => SCALAR, default => 'FATAL' },
34             channels => { type => ARRAYREF },
35             server => { type => SCALAR },
36             } );
37              
38             $self->_basic_init(%p);
39              
40             ($self->{'mbox'}, $self->{'private_group'} ) = Spread::connect( {
41             spread_name => $p{'server'},
42             private_name => SPREAD_PRIV,
43             group_membership => 0,
44             } );
45              
46              
47             if ( $sperrno ) {
48             croak "Could not join spread cluster. Error was: " . $sperrno;
49             }
50              
51             $self->{'joined'} = ();
52             ( $self->{'joined'} ) = grep Spread::join($self->{'mbox'}, $_), $p{'channels'};
53              
54             # What you need to do here is see if two arrays aer equal
55             unless ( $self->{'joined'} ) {
56             croak "Could not join spread cluster. Error was: " . $sperrno;
57             }
58              
59             return $self;
60              
61             }
62              
63             sub log_message {
64             my $self = shift;
65             my %p = @_;
66             Spread::multicast( $self->{'mbox'},
67             SAFE_MESS,
68             @{$self->{'joined'}},
69             LOG_MSG_TYPE,
70             $p{message},
71             );
72              
73             if ( $sperrno ) {
74             carp "Could not send a log message! Error was: " . $sperrno;
75             return undef;
76             }
77              
78             return $self;
79             }
80              
81             __END__