File Coverage

blib/lib/Test/Fluent/Logger.pm
Criterion Covered Total %
statement 27 27 100.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 13 13 100.0
pod 4 5 80.0
total 48 49 97.9


line stmt bran cond sub pod time code
1             package Test::Fluent::Logger;
2 5     5   148531 use 5.008001;
  5         21  
3 5     5   27 use strict;
  5         13  
  5         109  
4 5     5   24 use warnings;
  5         11  
  5         159  
5 5     5   25 no warnings qw/redefine/;
  5         17  
  5         420  
6              
7             our $VERSION = "0.03";
8              
9             require Exporter;
10             our @ISA = qw/Exporter/;
11             our @EXPORT = qw/get_fluent_logs clear_fluent_logs/;
12             our @EXPORT_OK = qw/is_active activate deactivate/;
13              
14 5     5   1941 use Fluent::Logger;
  5         262276  
  5         1137  
15              
16             my $original__post = Fluent::Logger->can('_post');
17              
18             my $is_active;
19             my @fluent_logs;
20              
21             sub is_active () {
22 7     7 0 3506 return $is_active;
23             }
24              
25             sub import {
26 4     4   384 Test::Fluent::Logger->export_to_level(1, @_);
27              
28 4         16 activate();
29              
30             *Fluent::Logger::_post = sub {
31 11 100   11   5794 if ($is_active) {
32 9         26 my ($self, $tag, $msg, $time) = @_;
33 9   100     144 push @fluent_logs, {
34             message => $msg,
35             time => $time,
36             tag_prefix => $self->tag_prefix || "",
37             };
38             } else {
39 2         11 $original__post->(@_);
40             }
41 4         5012 };
42             }
43              
44             sub unimport {
45 1     1   9 deactivate();
46             }
47              
48             sub activate () {
49 6     6 1 944 $is_active = 1;
50             }
51              
52             sub deactivate () {
53 3     3 1 1494 $is_active = 0;
54             }
55              
56             sub clear_fluent_logs () {
57 5     5 1 16270 @fluent_logs = ();
58             }
59              
60             sub get_fluent_logs () {
61 7     7 1 57 return @fluent_logs;
62             }
63              
64             1;
65             __END__