This file is indexed.

/usr/share/perl5/YAML/Shell.pm is in libyaml-shell-perl 0.71-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
use strict; use warnings;
package YAML::Shell;
our $VERSION = '0.71';

use Term::ReadLine;
sub Term::ReadLine::Perl::Tie::FIRSTKEY {undef}
use Data::Dumper;
use Config;
$Data::Dumper::Indent = 1;
our $prompt = 'ysh > ';
my $round_trip = 0;
my $force = 0;
my $log = 0;
my $yaml_module = 'YAML::Any';
my $yaml_version;
$| = 1;
my $sh;

sub run {
    my $class = shift;
    set_version($yaml_module);
    my @env_args = split /\s+/, ($ENV{YSH_OPT} || '');
    my @args = (@env_args, @_);
    my $stream = -t STDIN ? '' : join('', <STDIN>);
    while (my $arg = shift @args) {
        set_version($1), next if $arg =~ /^-M(.*)/;

        handle_help(), exit if $arg eq '-h';
        handle_version(), exit if $arg eq '-v';
        handle_Version(), exit if $arg eq '-V';

        $YAML::Indent = $1, next if $arg =~ /^-i(\d+)$/;
        $YAML::UseFold = 1, next if $arg eq '-uf';
        $YAML::UseBlock = 1, next if $arg eq '-ub';
        $YAML::UseCode = 1, next if $arg eq '-uc';
        $YAML::UseHeader = 0, next if $arg eq '-nh';
        $YAML::UseVersion = 0, next if $arg eq '-nv';
        $round_trip = 1, next if $arg eq '-r';
        $round_trip = 2, next if $arg eq '-R';
        $log = 1, next if $arg eq '-l';
        $log = 2, next if $arg eq '-L';
        $force = 1, next if $arg eq '-F';
        warn(<<END), exit 1;
Unknown YAML Shell argument: '$arg'.
For help, try: perldoc ysh
END
    }

    set_version($yaml_module);

    check_install() unless $force;

    if ($log) {
        if ($log == 2) {
            open LOGFILE, "> ./ysh.log" or die $!;
        }
        else {
            open LOGFILE, ">> ./ysh.log" or die $!;
        }
        no strict 'refs';
        my $version = ${"${yaml_module}::VERSION"};
        print LOGFILE "\n$yaml_module Version $version\n";
        print LOGFILE "Begin logging at ", scalar localtime, "\n\n";
    }

    if (not length($stream)) {
        Print(<<END);
Welcome to the YAML Test Shell (@{[ $class->implementation ]})

Type ':help' for more information.

END
    }

    {
        {
            local @ENV{qw(HOME EDITOR)};
            local $^W;
            $sh = Term::ReadLine::->new('The YAML Shell');
        }

        sub my_readline {
            print LOGFILE $prompt if $log;
            my $input = $sh->readline($prompt);
            if (not defined $input) {
                $input = ':exit';
                Print("\n");
            }
            $input .= "\n";
        }
    }

    if (length($stream)) {
        my @objects;
        no strict 'refs';
        eval { @objects = &{"${yaml_module}::Load"}($stream) };
        if ($@) {
            print STDERR $@;
            exit 1;
        }
        else {
            print STDOUT Data::Dumper::Dumper(@objects);
            exit 0;
        }
    }

    while ($_ = my_readline()) {
        print LOGFILE $_ if $log;
        next if /^\s*$/;
        exec('ysh', @ARGV) if /^\/$/;
        handle_command($_),next if /^:/;
        handle_file($1),next if /^<\s*(\S+)\s*$/;
        handle_yaml($_),next if /^--\S/;
        handle_yaml(''),next if /^===$/;
        handle_perl($_,1),next if /^;/;
        handle_perl($_,0),next;
        Print("Unknown command. Type ':help' for instructions.\n");
    }
}

sub set_version {
    my $module = shift;
    eval "require $module";
    die $@ if $@;
    $yaml_module = $module;
    no strict 'refs';
    $yaml_version = ${"${yaml_module}::VERSION"};
}

sub Print {
    print @_;
    print LOGFILE @_ if $log;
}
local $SIG{__WARN__} = sub { Print @_ };

sub handle_file {
    my ($file) = @_;
    my @objects;
    eval {
        no strict 'refs';
        @objects = &{"${yaml_module}::LoadFile"}($file)
    };
    if ($@) {
        Print $@;
    }
    else {
        Print Data::Dumper::Dumper(@objects);
    }
}

sub handle_perl {
    my ($perl, $multi) = @_;
    my (@objects, $yaml, $yaml2);
    local $prompt = 'perl> ';
    my $line = '';
    if ($multi) {
        while ($line !~ /^;$/) {
            $line = my_readline();
            print LOGFILE $line if $log;
            $perl .= $line;
        }
    }
    @objects = eval "no strict;$perl";
    Print("Bad Perl expression:\n$@"), return if $@;
    {
        no strict 'refs';
        eval { $yaml = &{"${yaml_module}::Dump"}(@objects) };
    }
    $@ =~ s/^ at.*\Z//sm if $@;
    Print("Dump failed:\n$@"), return if $@;
    Print $yaml;
    if ($round_trip) {
        {
            local $SIG{__WARN__} = sub {};
            no strict 'refs';
            eval { $yaml2 = &{"${yaml_module}::Dump"}(&{"${yaml_module}::Load"}($yaml)) };
        }
        $@ =~ s/^ at.*\Z//sm if $@;
        Print("Load failed:\n$@"), return if $@;
        if ($yaml eq $yaml2) {
            if ($round_trip > 1) {
                Print "\nData roundtripped OK!!!\n";
            }
        }
        else {
            Print "================\n";
            Print "after roundtrip:\n";
            Print "================\n";
            # $yaml2 =~ s/ /_/g;  #
            # $yaml2 =~ s/\n/+/g; #
            # Print $yaml2, "\n"; #
            Print $yaml2;
            Print "=========================\n";
            Print "Data did NOT roundtrip...\n";
        }
    }
}

sub handle_yaml {
    my $yaml = shift;
    my $line = $yaml;
    my (@objects);
    local $prompt = 'yaml> ';
    $line = my_readline();
    print LOGFILE $line if $log;
    $line = '' unless defined $line;
    while ($line !~ /^\.{3}$/) {
        $yaml .= $line;
        $line = my_readline();
        print LOGFILE $line if $log;
        last unless defined $line;
    }
    $yaml =~ s/\^{2,8}/\t/g;
    no strict 'refs';
    eval { @objects = &{"${yaml_module}::Load"}($yaml) };
    $@ =~ s/^ at.*\Z//sm if $@;
    $@ =~ s/^/  /gm if $@;
    Print("YAML Load Failed:\n$@"), return if $@;
    Print Data::Dumper::Dumper(@objects);
}

sub handle_command {
    my $line = shift;
    chomp $line;
    my ($cmd, $args);
    if ($line =~ /^:(\w+)\s*(.*)$/) {
        $cmd = $1;
        $args = $2;
        exit if $cmd =~ /^(exit|q(uit)?)$/;
        handle_help(),return if $cmd eq 'help';
        print `clear`,return if $cmd =~ /^c(lear)?$/;
    }
    Print "Invalid command\n";
}

sub handle_help {
    Print <<END;

       Welcome to the YAML Test Shell (@{[ __PACKAGE__->implementation ]})

   When you to type in Perl, you get back YAML. And vice versa.

   By default, every line you type is a one line Perl program, the return value
   of which will be displayed as YAML.

   To enter multi-line Perl code start the first line with ';' and use as many
   lines as needed. Terminate with a line containing just ';'.

   To enter YAML text, start with a valid YAML separator/header line which is
   typically '---'. Use '===' to indicate that there is no YAML header. Enter
   as many lines as needed. Terminate with a line containing just '...'.

   Shell Commands:             (Begin with ':')
      :exit or :q(uit) - leave the shell
      :help - get this help screen

END
}

sub implementation {
    my $module = $yaml_module;
    if ($yaml_module eq 'YAML::Any') {
        $module .= " -> " . YAML::Any->implementation;
    }
    return $module;
}

sub check_install {
    if (-f "./YAML.pm" && -f "./pm_to_blib" &&
        -M "./YAML.pm" <  -M "./pm_to_blib"
       ) {
        die "You need to 'make install'!\n";
    }
}

sub handle_version {
    print STDERR <<END;

ysh: '$VERSION'
${yaml_module}: '$yaml_version'

END
}

sub handle_Version {
    my $TRP = get_version('Term::ReadLine::Perl');
    my $TRG = get_version('Term::ReadLine::Gnu');
    my $POE = get_version('POE');
    my $TO = get_version('Time::Object');

    print STDERR <<END;

ysh: '$VERSION'
${yaml_module}: '$yaml_version'
perl: '$Config::Config{version}'
Data::Dumper: '$Data::Dumper::VERSION'
Term::ReadLine::Perl: '$TRP'
Term::ReadLine::Gnu: '$TRG'
POE: '$POE'
Time::Object: '$TO'

END
}

sub get_version {
    my ($module) = @_;
    my $version;
    eval "no strict; use $module; \$version = \$${module}::VERSION";
    #$version = "$@" if $@;
    $version = "not installed" if $@;
    return $version;
}

1;