File Coverage

blib/lib/Log/ger/Output/ArrayWithLimits.pm
Criterion Covered Total %
statement 17 17 100.0
branch 4 6 66.6
condition 2 3 66.6
subroutine 4 4 100.0
pod 0 1 0.0
total 27 31 87.1


line stmt bran cond sub pod time code
1             package Log::ger::Output::ArrayWithLimits;
2              
3             our $DATE = '2017-06-24'; # DATE
4             our $VERSION = '0.001'; # VERSION
5              
6 1     1   3717 use strict;
  1         4  
  1         28  
7 1     1   5 use warnings;
  1         2  
  1         171  
8              
9             sub get_hooks {
10 1     1 0 16 my %conf = @_;
11              
12 1 50       4 my $ary = $conf{array} or die "Please specify array";
13 1 50       4 ref $ary eq 'ARRAY' or die "Please specify arrayref in array";
14              
15             return {
16             create_log_routine => [
17             __PACKAGE__, 50,
18             sub {
19 6     6   1308 my %args = @_;
20              
21             my $logger = sub {
22 4         1651 my ($ctx, $msg) = @_;
23 4         13 push @$ary, $msg;
24 4 100 66     34 if (defined $conf{max_elems} && @$ary > $conf{max_elems}) {
25 1         6 shift @$ary;
26             }
27 6         20 };
28 6         21 [$logger];
29 1         9 }],
30             };
31             }
32              
33             1;
34             # ABSTRACT: Log to array, with some limits applied
35              
36             __END__
37              
38             =pod
39              
40             =encoding UTF-8
41              
42             =head1 NAME
43              
44             Log::ger::Output::ArrayWithLimits - Log to array, with some limits applied
45              
46             =head1 VERSION
47              
48             This document describes version 0.001 of Log::ger::Output::ArrayWithLimits (from Perl distribution Log-ger-Output-ArrayWithLimits), released on 2017-06-24.
49              
50             =head1 SYNOPSIS
51              
52             use Log::ger::Output ArrayWithLimits => (
53             array => $ary,
54             max_elems => 100, # defaults unlimited
55             );
56              
57             =head1 DESCRIPTION
58              
59             Currently only limiting number of elements is provided. Future limits will be
60             added.
61              
62             =for Pod::Coverage ^(.+)$
63              
64             =head1 CONFIGURATION
65              
66             =head1 HOMEPAGE
67              
68             Please visit the project's homepage at L<https://metacpan.org/release/Log-ger-Output-ArrayWithLimits>.
69              
70             =head1 SOURCE
71              
72             Source repository is at L<https://github.com/perlancar/perl-Log-ger-Output-ArrayWithLimits>.
73              
74             =head1 BUGS
75              
76             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Log-ger-Output-ArrayWithLimits>
77              
78             When submitting a bug or request, please include a test-file or a
79             patch to an existing test-file that illustrates the bug or desired
80             feature.
81              
82             =head1 SEE ALSO
83              
84             L<Log::ger>
85              
86             Modelled after L<Log::Dispatch::ArrayWithLimits>
87              
88             =head1 AUTHOR
89              
90             perlancar <perlancar@cpan.org>
91              
92             =head1 COPYRIGHT AND LICENSE
93              
94             This software is copyright (c) 2017 by perlancar@cpan.org.
95              
96             This is free software; you can redistribute it and/or modify it under
97             the same terms as the Perl 5 programming language system itself.
98              
99             =cut