AsYaml.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran n/a Conditioncond 66.6% 10 / 15 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 84.2% 59 / 70 CC 6 SCAR 10.7
CC
6
Cov
87%
BEGIN
6.4
BEGIN
1.3
BEGIN
1.0
CRAP 2.9
« Paths/2yaml.pm ↑ Summary
1 package Env::AsYaml;
2 # Last modified: Tue Sep 02 2025 01:10:52 PM -04:00 [EDT]
3 # First created: Sat Aug 09 2025 05:38:14 PM -04:00 [EDT]
4  
5 1 ▶use v5.18;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME/ABSTRACT
11  
12 Env::AsYaml is intended to be a tool for examination of the environment in
13 which the user is running programs, starting processes or for otherwise
14 troubleshooting the system.
15  
16 =head1 VERSION
17  
18 Version 0.35
19  
20 =cut
21  
22 our $VERSION = '0.35';
23  
24 =head1 SYNOPSIS
25  
26 This module checks the environment it's running in and prints it to STDOUT as
27 YAML. Env vars that are lists (such as C<$PATH>) are formatted in YAML as lists.
28  
29 use Env::AsYaml; # auto-imports 'showPathLists' and 'showScalars'
30  
31 =cut
32  
33 1 ▶use vars qw( @Wanted @Bare );
Subroutine BEGIN: called CC=1 SCAR=0.0
34 # ---------------------- ### ---------------------- #
35 1 ▶ BEGIN {
Subroutine BEGIN: called CC=6 SCAR=18.5
36 2 @Wanted = map { push @Bare=> $_; q%@% .$_ } grep {
37 1 ▶ $_ eq "PERL5LIB"
Condition66%10/15
$_ eq 'PERL5LIB' || $_ eq 'PATH' || /^XDG_[A-Z]+_DIRS\z/u || /^[_A-Z0-9]+PATH\z/u && !/^XDG_.+_PATH\z/u || /PSModulePath/iu
l!l&&r!l&&!r
2026
$_ eq "PERL5LIB" or $_ eq "PATH" or /^XDG_[A-Z]+_DIRS\z/u or /^[_A-Z0-9]+PATH\z/u and not /^XDG_.+_PATH\z/u
l!l&&r!l&&!r
2026
$_ eq "PERL5LIB" or $_ eq "PATH" or /^XDG_[A-Z]+_DIRS\z/u
l!l&&r!l&&!r
2026
$_ eq "PERL5LIB" or $_ eq "PATH"
l!l&&r!l&&!r
1126
/^[_A-Z0-9]+PATH\z/u and not /^XDG_.+_PATH\z/u
!ll&&!rl&&r
2600
MC/DC33%2/6
$_ eq 'PERL5LIB' || $_ eq 'PATH' || /^XDG_[A-Z]+_DIRS\z/u || /^[_A-Z0-9]+PATH\z/u && !/^XDG_.+_PATH\z/u || /PSModulePath/iu
$_ eq "PERL5LIB" $_ eq "PATH" /^XDG_[A-Z]+_DIRS\z/u /^[_A-Z0-9]+PATH\z/u not /^XDG_.+_PATH\z/u /PSModulePath/iu
Truth table37%3/8
A or B or C or D and not(E) || F
A= $_ eq "PERL5LIB"B= $_ eq "PATH"C= /^XDG_[A-Z]+_DIRS\z/uD= /^[_A-Z0-9]+PATH\z/uE= not /^XDG_.+_PATH\z/uF= /PSModulePath/iu
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
00011X1
0000X11
0001011
0000X00
0001000
38 || $_ eq "PATH"
39 || /^XDG_[A-Z]+_DIRS\z/
40 || ( /^[_A-Z0-9]+PATH\z/ && !/^XDG_.+_PATH\z/ )
41 || /PSModulePath/i # does not work on cygwin, why?
42 } sort keys %ENV;
43  
44 1 ▶ eval "use Env qw/@Wanted/ ;";
Subroutine BEGIN: called CC=1 SCAR=0.0
45 }
46 # ---------------------- ### ---------------------- #
47  
48 1 ▶use Env::Paths::2yaml;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use Env::Scalars::scalars2yaml;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶use YAML::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 require Exporter;
53 our @ISA = qw(Exporter);
54 our @EXPORT = qw(showPathLists showScalars);
55 0 ▶use Data::Dump::Color;
Subroutine BEGIN: called CC=1 SCAR=2.6
56 $Data::Dump::Color::INDEX = 0;
57 $Data::Dump::Color::COLOR = 'true';
58  
59 =head1 EXPORTS
60  
61 These subroutines are available to import ("@EXPORT_OK").
62 showPathLists showScalars
63  
64 =head1 SUBROUTINES/METHODS
65  
66 =head2 showPathLists
67  
68 Use Env::Paths::2yaml to transmute all env path lists into YAML serialization.
69  
70 =head2
71  
72 =cut
73  
74 sub showPathLists {
75 use Env::Paths::2yaml qw( ToYaml );
76 my $dd = defined $_[0] ? 'true' : '';
77 # It's nasty to hard-code it this way but this stuff in my env is just
78 # in the way:
79 @Bare = grep { $_ ne 'ORIGINAL_PATH'
80 && $_ ne 'AMDRMSDKPATH'
81 && $_ ne 'HOMEPATH' } @Bare;
82  
83 my( $accumulator , @all_docs );
84 for my $kstr ( @Bare ) {
85 no strict 'refs'; # a symbolic reference below:
86 my $seq = ToYaml( $kstr, @{$kstr} );
87 my $yaml_segment = join q[]=> @$seq;
88 $accumulator .= qq[\n---\n] . $yaml_segment;
89 }
90 print $accumulator;
91  
92 # Load YAML here, to dump the data in color if desired.
93 @all_docs = Load( $accumulator );
94  
95 if ($dd) { # Dump as perl data, in vivid technicolor.
96 print qq[\n];
97 dd( @all_docs );
98 }
99 }
100  
101 =head2 showScalars
102  
103 Print simple scalar strings present in the environment.
104  
105 =cut
106  
107 use Env::Scalars::scalars2yaml qw( s2yaml );
108 sub showScalars {
109 my $simples = s2yaml();
110 my $dd = defined $_[0] ? 'true' : '';
111 say qq[\n---];
112 say for @$simples;
113 if ($dd) {
114 dd( $simples );
115 }
116 }
117  
118 __END__
« Paths/2yaml.pm ↑ Summary