blib/lib/Narada/Log.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 85.0% 51 / 60 CC 8 SCAR 13.9
CC
8
Cov
86%
_init_log
7.5
import
3.0
BEGIN
1.0
CRAP 4.0
« Build ↑ Summary
1 package Narada::Log;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = 'v2.3.4';
8  
9 4 ▶use Narada::Config qw( get_config_line );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Log::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 4 _init_log();
14  
15  
16 sub import {
17 4 ▶ my @args = @_;
Subroutine import: called CC=3 SCAR=11.0
18 4 my $pkg = caller 0;
19 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 for (@args) {
21 7 ▶ if (m/\A\$(.*)/xms) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\A\$(.*)/msx) 3 4 7
22 3 *{$pkg.q{::}.$1} = \Log::Fast->global();
23 }
24 }
25 4 return;
26 }
27  
28 sub _init_log {
29 4 ▶ my $type = eval { get_config_line('log/type') } || 'syslog';
Subroutine _init_log: called CC=6 SCAR=20.2
Condition50%1/2
eval { || 'syslog'
l!l
40
MC/DC0%0/1
eval { do { get_config_line('log/type') } } || 'syslog'
eval { do { get_config_line('log/type') } }
Truth table50%1/2
A
A= eval { do { get_config_line('log/type') } }
Aresult
11
00
30 4 ▶ my $path = eval { get_config_line('log/output') } || return;
Condition50%1/2
eval { || (return)
l!l
40
MC/DC0%0/1
eval { do { get_config_line('log/output') } } || (return)
eval { do { get_config_line('log/output') } }
Truth table50%1/2
A
A= eval { do { get_config_line('log/output') } }
Aresult
11
00
31 4 ▶ if ($type eq 'syslog') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'syslog') { } 0 4 4
elsif ($type eq 'file') { } 4 0 4
32 0 Log::Fast->global()->config({
33 level => get_config_line('log/level'),
34 prefix => q{},
35 type => 'unix',
36 path => $path,
37 });
38 }
39 elsif ($type eq 'file') {
40 4 ▶ open my $fh, '>>', $path or croak "open: $!"; ## no critic (InputOutput::RequireBriefOpen)
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", $path or croak("open: $!") 0 4 4
41 4 Log::Fast->global()->config({
42 level => get_config_line('log/level'),
43 prefix => q{},
44 type => 'fh',
45 fh => $fh,
46 });
47 }
48 else {
49 0 croak "Unsupported value '$type' in config/log/type";
50 }
51 4 return;
52 }
53  
54  
55 4 1; # Magic true value required at end of module
56 __END__
57  
58 =encoding utf8
59  
60 =head1 NAME
61  
62 Narada::Log - setup project log
63  
64  
65 =head1 VERSION
66  
67 This document describes Narada::Log version v2.3.4
68  
69  
70 =head1 SYNOPSIS
71  
72 use Narada::Log qw( $LOG );
73  
74 $LOG->INFO("ready to work");
75  
76  
77 =head1 DESCRIPTION
78  
79 While loading, this module will configure Log::Fast->global() object
80 according to configuration in C<config/log/type>, C<config/log/output> and
81 C<config/log/level>.
82  
83 If any scalar variable names will be given as parameters while loading
84 module it will export Log::Fast->global() as given variable names.
85  
86 See L<Log::Fast> for more details.
87  
88  
89 =head1 INTERFACE
90  
91 None.
92  
93  
94 =head1 DIAGNOSTICS
95  
96 =over
97  
98 =item C<< open: %s >>
99  
100 File config/log/output contain file name, and error happens while trying to
101 open this file.
102  
103 =back
104  
105  
106 =head1 CONFIGURATION AND ENVIRONMENT
107  
108 Narada::Log requires configuration files and directories provided by
109 Narada framework.
110  
111  
112 =head1 SUPPORT
113  
114 =head2 Bugs / Feature Requests
115  
116 Please report any bugs or feature requests through the issue tracker
117 at L<https://github.com/powerman/Narada/issues>.
118 You will be notified automatically of any progress on your issue.
119  
120 =head2 Source Code
121  
122 This is open source software. The code repository is available for
123 public review and contribution under the terms of the license.
124 Feel free to fork the repository and submit pull requests.
125  
126 L<https://github.com/powerman/Narada>
127  
128 git clone https://github.com/powerman/Narada.git
129  
130 =head2 Resources
131  
132 =over
133  
134 =item * MetaCPAN Search
135  
136 L<https://metacpan.org/search?q=Narada>
137  
138 =item * CPAN Ratings
139  
140 L<http://cpanratings.perl.org/dist/Narada>
141  
142 =item * AnnoCPAN: Annotated CPAN documentation
143  
144 L<http://annocpan.org/dist/Narada>
145  
146 =item * CPAN Testers Matrix
147  
148 L<http://matrix.cpantesters.org/?dist=Narada>
149  
150 =item * CPANTS: A CPAN Testing Service (Kwalitee)
151  
152 L<http://cpants.cpanauthors.org/dist/Narada>
153  
154 =back
155  
156  
157 =head1 AUTHOR
158  
159 Alex Efros E<lt>powerman@cpan.orgE<gt>
160  
161  
162 =head1 COPYRIGHT AND LICENSE
163  
164 This software is Copyright (c) 2008-2016 by Alex Efros E<lt>powerman@cpan.orgE<gt>.
165  
166 This is free software, licensed under:
167  
168 The MIT (X11) License
169  
170  
171 =cut
« Build ↑ Summary