This file is indexed.

/usr/share/perl5/Test/Synopsis.pm is in libtest-synopsis-perl 0.15-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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
package Test::Synopsis;

use strict;
use warnings;
use 5.008_001;

our $VERSION = '0.15'; # VERSION

use parent qw( Test::Builder::Module );
our @EXPORT = qw( synopsis_ok all_synopsis_ok );

use ExtUtils::Manifest qw( maniread );
my %ARGS;
 # = ( dump_all_code_on_error => 1 ); ### REMOVE THIS FOR PRODUCTION!!!
sub all_synopsis_ok {
  %ARGS = @_;

  my $manifest = maniread();
  my @files = grep m!^lib/.*\.p(od|m)$!, keys %$manifest
  or __PACKAGE__->builder->skip_all('No files in lib to test');

  __PACKAGE__->builder->no_plan();

  synopsis_ok(@files);
}

sub synopsis_ok {
    my @files = @_;

    for my $file (@files) {
        my $blocks = _extract_synopsis($file);
        unless (@$blocks) {
            __PACKAGE__->builder->ok(1, "No SYNOPSIS code");
            next;
        }

        my $block_num = 0;
        for my $block (@$blocks) {
            $block_num++;
            my ($line, $code, $options) = @$block;

            # don't want __END__ blocks in SYNOPSIS chopping our '}' in wrapper sub
            # same goes for __DATA__ and although we'll be sticking an extra '}'
            # into its contents; it shouldn't matter since the code shouldn't be
            # run anyways.
            $code =~ s/(?=(?:__END__|__DATA__)\s*$)/}\n/m;

            $options = join(";", @$options);
            my $test   = qq($options;\nsub{\n#line $line "$file"\n$code\n;});
            #use Test::More (); Test::More::note "=========\n$test\n========";
            my $ok     = _compile($test);

            # See if the user is trying to skip this test using the =for block
            if ( !$ok and $@=~/^SKIP:.+BEGIN failed--compilation aborted/si ) {
                $@ =~ s/^SKIP:\s*//;
                $@ =~ s/\nBEGIN failed--compilation aborted at.+//s;
                __PACKAGE__->builder->skip($@, 1);
            } else {
                my $block_name = $file;
                ## Show block number only if more than one block
                if (@$blocks > 1) {
                    $block_name .= " (section $block_num)";
                }
                __PACKAGE__->builder->ok($ok, $block_name)
                    or __PACKAGE__->builder->diag(
                        $ARGS{dump_all_code_on_error}
                        ? "$@\nEVALED CODE:\n$test"
                        : $@
                    );
            }
        }
    }
}

my $sandbox = 0;
sub _compile {
    package
        Test::Synopsis::Sandbox;
    eval sprintf "package\nTest::Synopsis::Sandbox%d;\n%s",
      ++$sandbox, $_[0]; ## no critic
}

sub _extract_synopsis
{
    my $file = shift;

    my $parser = Test::Synopsis::Parser->new;
    $parser->parse_file($file);
    $parser->{tsyn_blocks}
}

package
  Test::Synopsis::Parser; # on new line to avoid indexing

use Pod::Simple 3.09;
use parent 'Pod::Simple';

sub new
{
    my $self = shift->SUPER::new(@_);
    $self->accept_targets('test_synopsis');
    $self->merge_text(1);
    $self->no_errata_section(1);
    $self->strip_verbatim_indent(sub {
        my $lines = shift;
        my ($indent) = $lines->[0] =~ /^(\s*)/;
        $indent
    });

    $self->{tsyn_stack} = [];
    $self->{tsyn_options} = [];
    $self->{tsyn_blocks} = [];
    $self->{tsyn_in_synopsis} = '';

    $self
}

sub _handle_element_start
{
    my ($self, $element_name, $attrs) = @_;

    #Test::More::note Test::More::explain($element_name);
    #Test::More::note Test::More::explain($attrs);
    push @{$self->{tsyn_stack}}, [ $element_name, $attrs ];
}

sub _handle_element_end
{
    return unless $_[0]->{tsyn_stack};
    pop @{ $_[0]->{tsyn_stack} };
}

sub _handle_text
{
    return unless $_[0]->{tsyn_stack};
    my ($self, $text) = @_;
    my $elt = $self->{tsyn_stack}[-1][0];
    if ($elt eq 'head1') {
        if ($self->{tsyn_in_synopsis}) {
            # Exiting SYNOPSIS => Skip everything to the end
            delete $self->{tsyn_stack};
        }
        $self->{tsyn_in_synopsis} = $text =~ /SYNOPSIS\s*$/;
    } elsif ($elt eq 'Data') {
        # use Test::More; Test::More::note "XXX";
        my $up = $self->{tsyn_stack}[-2];
        if ($up->[0] eq 'for' && $up->[1]->{target} eq 'test_synopsis') {
            my $line = $up->[1]{start_line};
            my $file = $self->source_filename;
            push @{$self->{tsyn_options}}, qq<#line $line "$file"\n$text\n>;
        }
    } elsif ($elt eq 'Verbatim' && $self->{tsyn_in_synopsis}) {
        my $line = $self->{tsyn_stack}[-1][1]{start_line};
        push @{ $self->{tsyn_blocks} }, [
            $line,
            $text,
            $self->{tsyn_options},
        ];
        $self->{tsyn_options} = [];
    }
}


1;
__END__

=encoding utf-8

=for stopwords Goro blogged Znet Zoffix DOHERTY Doherty
  KRYDE Ryde ZOFFIX Gr nauer Grünauer pm HEREDOC HEREDOCs DROLSKY

=for test_synopsis $main::for_checked=1

=head1 NAME

Test::Synopsis - Test your SYNOPSIS code

=head1 SYNOPSIS

  # xt/synopsis.t (with Module::Install::AuthorTests)
  use Test::Synopsis;
  all_synopsis_ok();

  # Or, run safe without Test::Synopsis
  use Test::More;
  eval "use Test::Synopsis";
  plan skip_all => "Test::Synopsis required for testing" if $@;
  all_synopsis_ok();

=head1 DESCRIPTION

Test::Synopsis is an (author) test module to find .pm or .pod files
under your I<lib> directory and then make sure the example snippet
code in your I<SYNOPSIS> section passes the perl compile check.

Note that this module only checks the perl syntax (by wrapping the
code with C<sub>) and doesn't actually run the code, B<UNLESS>
that code is a C<BEGIN {}> block or a C<use> statement.

Suppose you have the following POD in your module.

  =head1 NAME

  Awesome::Template - My awesome template

  =head1 SYNOPSIS

    use Awesome::Template;

    my $template = Awesome::Template->new;
    $tempalte->render("template.at");

  =head1 DESCRIPTION

An user of your module would try copy-paste this synopsis code and
find that this code doesn't compile because there's a typo in your
variable name I<$tempalte>. Test::Synopsis will catch that error
before you ship it.

=head1 VARIABLE DECLARATIONS

Sometimes you might want to put some undeclared variables in your
synopsis, like:

  =head1 SYNOPSIS

    use Data::Dumper::Names;
    print Dumper($scalar, \@array, \%hash);

This assumes these variables like I<$scalar> are defined elsewhere in
module user's code, but Test::Synopsis, by default, will complain that
these variables are not declared:

    Global symbol "$scalar" requires explicit package name at ...

In this case, you can add the following POD sequence elsewhere in your POD:

  =for test_synopsis
  no strict 'vars'

Or more explicitly,

  =for test_synopsis
  my($scalar, @array, %hash);

Test::Synopsis will find these C<=for> blocks and these statements are
prepended before your SYNOPSIS code when being evaluated, so those
variable name errors will go away, without adding unnecessary bits in
SYNOPSIS which might confuse users.

=head1 SKIPPING TEST FROM INSIDE THE POD

You can use a C<BEGIN{}> block in the C<=for test_synopsis> to check for
specific conditions (e.g. if a module is present), and possibly skip
the test.

If you C<die()> inside the C<BEGIN{}> block and the die message begins
with sequence C<SKIP:> (note the colon at the end), the test
will be skipped for that document.

  =head1 SYNOPSIS

  =for test_synopsis BEGIN { die "SKIP: skip this pod, it's horrible!\n"; }

      $x; # undeclared variable, but we skipped the test!

  =end

=head1 EXPORTED SUBROUTINES

=head2 C<all_synopsis_ok>

  all_synopsis_ok();

  all_synopsis_ok( dump_all_code_on_error => 1 );

Checks the SYNOPSIS code in all your modules. Takes B<optional>
arguments as key/value pairs. Possible arguments are as follows:

=head3 C<dump_all_code_on_error>

  all_synopsis_ok( dump_all_code_on_error => 1 );

Takes true or false values as a value. B<Defaults to:> false. When
set to a true value, if an error is discovered in the SYNOPSIS code,
the test will dump the entire snippet of code it tried to test. Use this
if you want to copy/paste and play around with the code until the error
is fixed.

The dumped code will include any of the C<=for> code you specified (see
L<VARIABLE DECLARATIONS> section above) as well as a few internal bits
this test module uses to make SYNOPSIS code checking possible.

B<Note:> you will likely have to remove the C<#> and a space at the start
of each line (C<perl -pi -e 's/^#\s//;' TEMP_FILE_WITH_CODE>)

=head2 C<synopsis_ok>

  use Test::More tests => 1;
  use Test::Synopsis;
  synopsis_ok("t/lib/NoPod.pm");
  synopsis_ok(qw/Pod1.pm  Pod2.pm  Pod3.pm/);

Lets you test a single file. B<Note:> you must setup your own plan if
you use this subroutine (e.g. with C<< use Test::More tests => 1; >>).
B<Takes> a list of filenames for documents containing SYNOPSIS code to test.

=head1 CAVEATS

This module will not check code past the C<__END__> or
C<__DATA__> tokens, if one is
present in the SYNOPSIS code.

This module will actually execute C<use> statements and any code
you specify in the C<BEGIN {}> blocks in the SYNOPSIS.

If you're using HEREDOCs in your SYNOPSIS, you will need to place
the ending of the HEREDOC at the same indent as the
first line of the code of your SYNOPSIS.

Redefinition warnings can be turned off with

  =for test_synopsis
  no warnings 'redefine';

=head1 REPOSITORY

Fork this module on GitHub:
L<https://github.com/miyagawa/Test-Synopsis>

=head1 BUGS

To report bugs or request features, please use
L<https://github.com/miyagawa/Test-Synopsis/issues>

If you can't access GitHub, you can email your request
to C<bug-Test-Synopsis at rt.cpan.org>

=head1 AUTHOR

Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>

Goro Fuji blogged about the original idea at
L<http://d.hatena.ne.jp/gfx/20090224/1235449381> based on the testing
code taken from L<Test::Weaken>.

=head1 MAINTAINER

Zoffix Znet <cpan (at) zoffix.com>

=head1 CONTRIBUTORS

=over 4

=item * Dave Rolsky (L<DROLSKY|https://metacpan.org/author/DROLSKY>)

=item * Kevin Ryde (L<KRYDE|https://metacpan.org/author/KRYDE>)

=item * Marcel Grünauer (L<MARCEL|https://metacpan.org/author/MARCEL>)

=item * Mike Doherty (L<DOHERTY|https://metacpan.org/author/DOHERTY>)

=item * Patrice Clement (L<monsieurp|https://github.com/monsieurp>)

=item * Greg Sabino Mullane (L<TURNSTEP|https://metacpan.org/author/TURNSTEP>)

=item * Zoffix Znet (L<ZOFFIX|https://metacpan.org/author/ZOFFIX>)

=item * Olivier Mengué (L<DOLMEN|https://metacpan.org/author/DOLMEN>)

=back

=head1 LICENSE

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 COPYRIGHT

This library is Copyright (c) Tatsuhiko Miyagawa

=head1 SEE ALSO

L<Test::Pod>, L<Test::UseAllModules>, L<Test::Inline>

=cut