| 1 | # | ||||||||||
| 2 | # Copyright (c) 2015-2021 Christian Jaeger, copying@christianjaeger.ch | ||||||||||
| 3 | # | ||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||
| 7 | # bundled with this file. | ||||||||||
| 8 | # | ||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | Chj::pp -- pretty printing as a debugging help | ||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | use Chj::pp; | ||||||||||
| 17 | |||||||||||
| 18 | print pp (1/2) + 1, "\n"; # prints "0.5\n" to stderr then "1.5\n" to stdout | ||||||||||
| 19 | |||||||||||
| 20 | print pp_ ("x", 1/2) + 1, "\n"; # prints "x: 0.5\n" to stderr then see above | ||||||||||
| 21 | |||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | =head1 NOTE | ||||||||||
| 26 | |||||||||||
| 27 | This is alpha software! Read the status section in the package README | ||||||||||
| 28 | or on the L<website|http://functional-perl.org/>. | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | package Chj::pp; | ||||||||||
| 33 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 1 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 1 | ▶ | use Exporter "import"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | |||||||||||
| 38 | 1 | our @EXPORT = qw(pp pp_); | |||||||||
| 39 | 1 | our @EXPORT_OK = qw(); | |||||||||
| 40 | 1 | our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||
| 41 | |||||||||||
| 42 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 1 | ▶ | use Chj::TerseDumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub Dump { | ||||||||
|
Subroutine
Dump: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 46 | 0 | ▶ | @_ > 1 ? Dumper(@_) : TerseDumper(@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub pp { | ||||||||
|
Subroutine
pp: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 50 | 0 | print STDERR Dump(@_); | |||||||||
| 51 | 0 | ▶ | wantarray ? @_ : $_[-1] ## no critic | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub pp_ { | ||||||||
|
Subroutine
pp_: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 55 | 0 | my $msg = shift; | |||||||||
| 56 | 0 | ▶ | print STDERR "$msg:", (@_ > 1 ? "\n" : " "), Dump(@_); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | ▶ | wantarray ? @_ : $_[-1] ## no critic | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 1 | 1 | |||||||||