File Coverage

lib/ChordPro/Logger.pm
Criterion Covered Total %
statement 35 52 67.3
branch 2 4 50.0
condition n/a
subroutine 8 11 72.7
pod n/a
total 45 67 67.1


line stmt bran cond sub pod time code
1             #! perl
2              
3 90     90   707 use strict;
  90         259  
  90         5365  
4              
5             package ChordPro::Logger;
6              
7 90     90   689 use feature 'signatures';
  90         235  
  90         11825  
8 90     90   732 no warnings 'experimental::signatures';
  90         184  
  90         4629  
9              
10 90     90   551 use Carp;
  90         265  
  90         58417  
11             $Carp::Internal{ (__PACKAGE__) }++;
12              
13             # die => fatal
14             # warn ? => error
15             # warn ! => warning
16             # warn => informational
17              
18 4     4   12 sub _warn(@msg) {
  4         13  
  4         9  
19 4         20 __warn( \&CORE::warn, @msg );
20             }
21 2     2   6 sub _die(@msg) {
  2         10  
  2         4  
22 2         8 __warn( \&CORE::die, @msg );
23             }
24              
25 6     6   17 sub __warn( $proc, @msg ) {
  6         11  
  6         18  
  6         17  
26 6         34 my $msg = shift(@msg);
27 6         25 $msg =~ s/^[?!]//;
28 6 50       30 if ( $ENV{CHORDPRO_CARP_VERBOSE} ) {
29 0         0 $msg .= join( '', @msg );
30 0         0 $msg =~ s/\n+$//;
31 0         0 Carp::cluck( $msg );
32             }
33             else {
34 6         22 $msg .= join( '', @msg );
35 6 50       50 if ( $msg =~ s/\n+$// ) {
36 6         1310 $msg = Carp::shortmess($msg);
37 6         31 chomp($msg);
38 6         60 $msg =~ s/ at .* line \d+\.$//s;
39             }
40             else {
41 0         0 $msg = Carp::shortmess($msg);
42 0         0 chomp($msg);
43             }
44 6         87 $proc->($msg."\n");
45             }
46             }
47              
48             BEGIN {
49 90     90   582 *CORE::GLOBAL::warn = \&_warn;
50 90         19418 *CORE::GLOBAL::die = \&_die;
51             }
52              
53             1;
54              
55             package main;
56              
57             unless ( caller ) {
58             require Carp;
59 0     0     sub a($x) { b($x) }
  0            
  0            
  0            
60 0     0     sub b($x) { c($x) }
  0            
  0            
  0            
61 0     0     sub c($x) { Carp::cluck($x) }
  0            
  0            
  0            
62             a("Hi");
63             }
64