File Coverage

lib/Log/Shiras/Report.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


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