| 1 | package Log::Sigil; | ||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 7 | ▶ | use Exporter "import"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 7 | ▶ | use List::Util qw( max ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 7 | ▶ | use constant DEBUG => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 7 | our @EXPORT = qw( swarn swarn2 ); | |||||||||
| 10 | 7 | our $VERSION = "1.02"; | |||||||||
| 11 | |||||||||||
| 12 | 7 | our @SIGILS = ( | |||||||||
| 13 | qw( | ||||||||||
| 14 | = | ||||||||||
| 15 | + | ||||||||||
| 16 | ! | ||||||||||
| 17 | @ | ||||||||||
| 18 | ), | ||||||||||
| 19 | q{#}, | ||||||||||
| 20 | qw( | ||||||||||
| 21 | $ | ||||||||||
| 22 | % | ||||||||||
| 23 | ^ | ||||||||||
| 24 | & | ||||||||||
| 25 | * | ||||||||||
| 26 | - | ||||||||||
| 27 | | | ||||||||||
| 28 | \ | ||||||||||
| 29 | ~ | ||||||||||
| 30 | ? | ||||||||||
| 31 | ), | ||||||||||
| 32 | ); | ||||||||||
| 33 | 7 | our $TIMES = 3; | |||||||||
| 34 | 7 | our $SEPARATOR = q{ }; | |||||||||
| 35 | 7 | our $BIAS = 0; | |||||||||
| 36 | 7 | our %INDEX = ( "main::" => 0 ); # Ensure `values` + 1 is the next. | |||||||||
| 37 | 7 | my $ANON_REGEX = qr{ (?: .*::__ANON__ | [(]eval[)] ) \z}msx; | |||||||||
| 38 | |||||||||||
| 39 | 16 | ▶ | sub swarn { | ||||||||
|
Subroutine
swarn: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||
| 40 | 16 | my $nth = 0; | |||||||||
| 41 | 16 | my $bias = 1; | |||||||||
| 42 | |||||||||||
| 43 | 16 | ▶ | $nth++ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | while caller $nth; | ||||||||||
| 45 | |||||||||||
| 46 | 16 | my( $package, $filename, $line, $subroutine ) = caller $nth - $bias - $BIAS; | |||||||||
| 47 | |||||||||||
| 48 | 16 | $bias++; | |||||||||
| 49 | |||||||||||
| 50 | 16 | ▶ | $subroutine = "main::" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | if $subroutine eq join q{::}, __PACKAGE__, "swarn"; | ||||||||||
| 52 | |||||||||||
| 53 | 16 | ▶ | $subroutine = "${subroutine}::$line" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | if $subroutine =~ m{$ANON_REGEX}; | ||||||||||
| 55 | |||||||||||
| 56 | 16 | ▶ | $bias++ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | if $subroutine =~ m{$ANON_REGEX}; | ||||||||||
| 58 | |||||||||||
| 59 | 16 | ▶ | if ( my @list = caller $nth - $bias - $BIAS ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 14 | ( undef, undef, $line ) = @list; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 16 | warn "\$package:\t$package" if DEBUG; | |||||||||
| 64 | 16 | warn "\$filename:\t$filename" if DEBUG; | |||||||||
| 65 | 16 | warn "\$line:\t$line" if DEBUG; | |||||||||
| 66 | 16 | warn "\$subroutine:\t$subroutine" if DEBUG; | |||||||||
| 67 | |||||||||||
| 68 | 16 | ▶ | unless ( exists $INDEX{ $subroutine } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 8 | $INDEX{ $subroutine } = max( values %INDEX ) + 1; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 16 | my $sigil = $SIGILS[ $INDEX{ $subroutine } % @SIGILS ]; | |||||||||
| 73 | 16 | warn "\$sigil:\t$sigil" if DEBUG; | |||||||||
| 74 | 16 | unshift @_, $sigil x $TIMES, $SEPARATOR; | |||||||||
| 75 | 16 | push @_, " by ${filename}[$line]: $subroutine\n"; # Ignore if original has \n at the end. | |||||||||
| 76 | |||||||||||
| 77 | 16 | warn @_; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 2 | ▶ | sub swarn2 { | ||||||||
|
Subroutine
swarn2: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 81 | 2 | local $BIAS = $BIAS + 1; | |||||||||
| 82 | 2 | &swarn; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 7 | 1; | |||||||||
| 86 | __END__ | ||||||||||