File Coverage

blib/lib/Message/Passing/Role/HasErrorChain.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Message::Passing::Role::HasErrorChain;
2 10     10   3845 use Moo::Role;
  10         20  
  10         62  
3 10     10   3292 use Module::Runtime qw/ require_module /;
  10         33  
  10         70  
4 10     10   569 use namespace::clean -except => 'meta';
  10         23  
  10         67  
5              
6             has error => (
7             is => 'ro',
8             lazy => 1,
9             builder => '_build_default_error_chain',
10             );
11              
12             sub _build_default_error_chain {
13 4     4   66 require_module 'Message::Passing::Output::STDERR';
14 4         117 require_module 'Message::Passing::Filter::Encoder::JSON';
15 4         60 Message::Passing::Filter::Encoder::JSON->new(
16             output_to => Message::Passing::Output::STDERR->new,
17             );
18             }
19              
20             1;
21              
22             =head1 NAME
23              
24             Message::Passing::Role::HasErrorChain - A role for components which can report errors
25              
26             =head1 SYNOPSIS
27              
28             # Note this is an example package, and does not really exist!
29             package Message::Passing::Output::ErrorAllMessages;
30             use Moo;
31             use namespace::clean -except => 'meta';
32              
33             with qw/
34             Message::Passing::Role::Output
35             Message::Passing::Role::HasErrorChain
36             /;
37              
38             sub consume {
39             my ($self, $message) = @_;
40             $self->error->consume($message);
41             }
42              
43             =head1 DESCRIPTION
44              
45             Some components can create an error stream in addition to a message stream.
46              
47             =head1 METHODS
48              
49             =head2 error
50              
51             An attribute containing the error chain.
52              
53             By default, this is a chain of:
54              
55             =over
56              
57             =item Message::Passing::Filter::Encoder::JSON
58              
59             =item Message::Passing::Output::STDOUT
60              
61             =back
62              
63             =head1 WARNINGS
64              
65             =head2 ERROR CHAINS CAN LOOP
66              
67             If you override the error chain output, be sure that the error chain does not go into your
68             normal log path! This is because if you suddenly have errors in your normal log path, and you
69             then start logging these errors, this causes more errors - causing you to generate a message loop.
70              
71             =head2 ENCODING IN ERROR CHAINS
72              
73             If you emit something which cannot be encoded to an error chain then the encoding
74             error will likely be emitted by the error chain - this can again cause loops and other
75             issues.
76              
77             All components which use error chains should be very careful to output data which
78             they are entirely certain will be able to be encoded.
79              
80             =head1 SPONSORSHIP
81              
82             This module exists due to the wonderful people at Suretec Systems Ltd.
83             <http://www.suretecsystems.com/> who sponsored its development for its
84             VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with
85             the SureVoIP API -
86             <http://www.surevoip.co.uk/support/wiki/api_documentation>
87              
88             =head1 AUTHOR, COPYRIGHT AND LICENSE
89              
90             See L<Message::Passing>.
91              
92             =cut
93