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   4494 use Moo::Role;
  10         18  
  10         69  
3 10     10   3614 use Module::Runtime qw/ require_module /;
  10         16  
  10         61  
4 10     10   525 use namespace::clean -except => 'meta';
  10         17  
  10         82  
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   1419 require_module 'Message::Passing::Output::STDERR';
14 4         120 require_module 'Message::Passing::Filter::Encoder::JSON';
15 4         81 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             who sponsored its development for its
84             VoIP division called SureVoIP for use with
85             the SureVoIP API -
86            
87              
88             =head1 AUTHOR, COPYRIGHT AND LICENSE
89              
90             See L.
91              
92             =cut
93