File Coverage

lib/Log/Shiras/Report.pm
Criterion Covered Total %
statement 26 26 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 35 35 100.0


line stmt bran cond sub pod time code
1             package Log::Shiras::Report;
2             our $AUTHORITY = 'cpan:JANDREW';
3 1     1   797459 use version; our $VERSION = version->declare("v0.46.0");
  1         1  
  1         6  
4 1     1   71 use strict;
  1         1  
  1         15  
5 1     1   3 use warnings;
  1         1  
  1         16  
6 1     1   14 use 5.010;
  1         3  
7 1     1   3 use utf8;
  1         1  
  1         5  
8             #~ use lib '../../';
9             #~ use Log::Shiras::Unhide qw( :InternalReporT );
10             ###InternalReporT warn "You uncovered internal logging statements for Log::Shiras::Report-$VERSION" if !$ENV{hide_warn};
11             ###InternalReporT use Log::Shiras::Switchboard;
12             ###InternalReporT my $switchboard = Log::Shiras::Switchboard->instance;
13 1     1   25 use Carp qw( confess cluck );
  1         2  
  1         53  
14 1     1   4 use MooseX::Types::Moose qw( ArrayRef HashRef );
  1         1  
  1         6  
15 1     1   3095 use Moose::Role;
  1         1  
  1         7  
16             requires 'add_line';
17              
18             #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9
19              
20              
21              
22             #########1 Public Methods 3#########4#########5#########6#########7#########8#########9
23              
24              
25              
26             #########1 Private Attributes 3#########4#########5#########6#########7#########8#########9
27            
28              
29              
30             #########1 Private Methods 3#########4#########5#########6#########7#########8#########9
31              
32             around add_line => sub{
33             my( $_add_line, $self, $message_ref ) = @_;
34             ###InternalReporT $switchboard->master_talk( { report => 'log_file', level => 1,
35             ###InternalReporT name_space => 'Log::Shiras::Report::add_line',
36             ###InternalReporT message =>[ 'Scrubbing the message ref:', $message_ref ], } );
37            
38             # Scrub the input
39             if( !is_HashRef( $message_ref ) ){
40             confess "Expected the message to be passed as a hashref";
41             }elsif( !exists $message_ref->{message} ){
42             cluck "Passing an empty message to the report";
43             $message_ref->{message} = [];
44             ###InternalReporT $switchboard->master_talk( { report => 'log_file', level => 3,
45             ###InternalReporT name_space => 'Log::Shiras::Report::CSVFile::add_line',
46             ###InternalReporT message =>[ 'Message ref has no message:', $message_ref ], } );
47             }elsif( !is_ArrayRef( $message_ref->{message} ) ){
48             confess "The passed 'message' key value is not an array ref";
49             }
50            
51             # Check for a manage_message add on
52             if( $self->can( 'manage_message' ) ){
53             $message_ref = $self->manage_message( $message_ref );
54             ###InternalReporT $switchboard->master_talk( { report => 'log_file', level => 3,
55             ###InternalReporT name_space => 'Log::Shiras::Report::CSVFile::add_line',
56             ###InternalReporT message =>[ 'Updated the message to:', $message_ref->{message} ], } );
57             }
58            
59             # Implement the method
60             my $times = $self->$_add_line( $message_ref );
61             ###InternalReporT $switchboard->master_talk( { report => 'log_file', level => 2,
62             ###InternalReporT name_space => 'Log::Shiras::Report::add_line',
63             ###InternalReporT message =>[ 'add_line wrap finished', $times, $message_ref ], } );
64             return $times;
65             };
66            
67              
68             #########1 Phinish 3#########4#########5#########6#########7#########8#########9
69              
70 1     1   3232 no Moose::Role;
  1         1  
  1         6  
71              
72             1;
73             # The preceding line will help the module return a true value
74              
75             #########1 main pod docs 3#########4#########5#########6#########7#########8#########9
76             __END__
77              
78             =head1 NAME
79              
80             Log::Shiras::Report - Report Role (Interface) for Log::Shiras
81              
82             =head1 SYNOPSIS
83              
84             use Modern::Perl;
85             use Log::Shiras::Switchboard;
86             use Log::Shiras::Report;
87             use Log::Shiras::Report::CSVFile;
88             my $operator = Log::Shiras::Switchboard->get_operator(
89             name_space_bounds =>{
90             UNBLOCK =>{
91             to_file => 'info',# for info and more urgent messages
92             },
93             },
94             reports =>{
95             to_file =>[{
96             superclasses =>[ 'Log::Shiras::Report::CSVFile' ],
97             add_roles_in_sequence =>[
98             'Log::Shiras::Report',
99             'Log::Shiras::Report::MetaMessage',
100             ],# Effectivly an early class type check
101             file => 'test.csv',
102             }],
103             }
104             );
105            
106             =head1 DESCRIPTION
107              
108             This is a simple interface that ensures the report object has an 'add_line' method. It also
109             scrubs the input to 'add_line' method to ensure the message is a hashref with the key message.
110             Finally, it calls a method 'manage_message' if it has been composed into the larger class.
111             For an example see L<Log::Shiras::Report::MetaMessage>. If you wish to build your own report
112             object it just has to have an add_line method. To use the report it is registered to the
113             switchboard using L<Log::Shiras::Switchboard/reports> For an example of a simple report see
114             L<Log::Shiras::Report::Stdout> For an example of a complex report see
115             L<Log::Shiras::Report::CSVFile> Upon registration the reports will receive their messages from
116             L<Log::Shiras::Switchboard/master_talk( $args_ref )>.
117              
118             =head1 SUPPORT
119              
120             =over
121              
122             L<Log-Shiras/issues|https://github.com/jandrew/Log-Shiras/issues>
123              
124             =back
125              
126             =head1 TODO
127              
128             =over
129              
130             B<1.> Nothing L<currently|/SUPPORT>
131              
132             =back
133              
134             =head1 AUTHOR
135              
136             =over
137              
138             =item Jed Lund
139              
140             =item jandrew@cpan.org
141              
142             =back
143              
144             =head1 COPYRIGHT
145              
146             This program is free software; you can redistribute
147             it and/or modify it under the same terms as Perl itself.
148              
149             The full text of the license can be found in the
150             LICENSE file included with this module.
151              
152             =head1 DEPENDENCIES
153              
154             =over
155              
156             L<version>
157              
158             L<Moose::Role> - requires (add_line)
159              
160             L<MooseX::Types::Moose>
161              
162             L<Carp> - confess cluck
163              
164             =back
165              
166             =cut
167              
168             #########1#########2 main pod documentation end 5#########6#########7#########8#########9