| 1 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | package Log::Dispatch::Array 1.005; | ||||||||||||
| 4 | 1 | ▶ | use parent qw(Log::Dispatch::Output); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | # ABSTRACT: log events to an array (reference) | ||||||||||||
| 6 | |||||||||||||
| 7 | #pod =head1 SYNOPSIS | ||||||||||||
| 8 | #pod | ||||||||||||
| 9 | #pod use Log::Dispatch; | ||||||||||||
| 10 | #pod use Log::Dispatch::Array; | ||||||||||||
| 11 | #pod | ||||||||||||
| 12 | #pod my $log = Log::Dispatch->new; | ||||||||||||
| 13 | #pod | ||||||||||||
| 14 | #pod my $target = []; | ||||||||||||
| 15 | #pod | ||||||||||||
| 16 | #pod $log->add(Log::Dispatch::Array->new( | ||||||||||||
| 17 | #pod name => 'text_table', | ||||||||||||
| 18 | #pod min_level => 'debug', | ||||||||||||
| 19 | #pod array => $target, | ||||||||||||
| 20 | #pod )); | ||||||||||||
| 21 | #pod | ||||||||||||
| 22 | #pod $log->warn($_) for @events; | ||||||||||||
| 23 | #pod | ||||||||||||
| 24 | #pod # now $target refers to an array of events | ||||||||||||
| 25 | #pod | ||||||||||||
| 26 | #pod =head1 DESCRIPTION | ||||||||||||
| 27 | #pod | ||||||||||||
| 28 | #pod This provides a Log::Dispatch log output system that appends logged events to | ||||||||||||
| 29 | #pod an array reference. This is probably only useful for testing the logging of | ||||||||||||
| 30 | #pod your code. | ||||||||||||
| 31 | #pod | ||||||||||||
| 32 | #pod =method new | ||||||||||||
| 33 | #pod | ||||||||||||
| 34 | #pod my $table_log = Log::Dispatch::Array->new(\%arg); | ||||||||||||
| 35 | #pod | ||||||||||||
| 36 | #pod This method constructs a new Log::Dispatch::Array output object. Valid | ||||||||||||
| 37 | #pod arguments are: | ||||||||||||
| 38 | #pod | ||||||||||||
| 39 | #pod array - a reference to an array to append to; defaults to an attr on | ||||||||||||
| 40 | #pod $table_log | ||||||||||||
| 41 | #pod | ||||||||||||
| 42 | #pod =cut | ||||||||||||
| 43 | |||||||||||||
| 44 | 1 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 45 | 1 | my ($class, %arg) = @_; | |||||||||||
| 46 | 1 | ▶ | $arg{array} ||= []; | ||||||||||
|
Condition50%1/2
$arg{"array"} ||= []
MC/DC0%0/1
$arg{"array"} ||= []
$arg{"array"}
Truth table50%1/2
A
A= $arg{"array"}
| |||||||||||||
| 47 | |||||||||||||
| 48 | 1 | my $self = { array => $arg{array} }; | |||||||||||
| 49 | |||||||||||||
| 50 | 1 | bless $self => $class; | |||||||||||
| 51 | |||||||||||||
| 52 | # this is our duty as a well-behaved Log::Dispatch plugin | ||||||||||||
| 53 | 1 | $self->_basic_init(%arg); | |||||||||||
| 54 | |||||||||||||
| 55 | 1 | return $self; | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | #pod =method array | ||||||||||||
| 59 | #pod | ||||||||||||
| 60 | #pod This method returns a reference to the array to which logging is being | ||||||||||||
| 61 | #pod performed. | ||||||||||||
| 62 | #pod | ||||||||||||
| 63 | #pod =cut | ||||||||||||
| 64 | |||||||||||||
| 65 | 3 | ▶ | sub array { $_[0]->{array} } | ||||||||||
|
Subroutine
array: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 66 | |||||||||||||
| 67 | #pod =method log_message | ||||||||||||
| 68 | #pod | ||||||||||||
| 69 | #pod This is the method which performs the actual logging, as detailed by | ||||||||||||
| 70 | #pod Log::Dispatch::Output. | ||||||||||||
| 71 | #pod | ||||||||||||
| 72 | #pod =cut | ||||||||||||
| 73 | |||||||||||||
| 74 | 2 | ▶ | sub log_message { | ||||||||||
|
Subroutine
log_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 75 | 2 | my ($self, %p) = @_; | |||||||||||
| 76 | 2 | push @{ $self->array }, { %p }; | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | 1 | 1; | |||||||||||
| 80 | |||||||||||||
| 81 | __END__ | ||||||||||||