9 use base 'Test::Inline::Extract';
11 use List::Util qw( first );
13 # This extracts the SYNOPSIS in addition to code specifically
16 (?:^|\n) # After the beginning of the string, or a newline
17 ( # ... start capturing
19 package\s+ # A package
20 [^\W\d]\w*(?:(?:\'|::)[^\W\d]\w*)* # ... with a name
21 \s*; # And a statement terminator
23 =head1[ \t]+SYNOPSIS\n
27 =for[ \t]+example[ \t]+begin\n # ... when we find a =for example begin
28 .*? # ... and keep capturing
29 \n=for[ \t]+example[ \t]+end\s*? # ... until the =for example end
30 (?:\n|$) # ... at the end of file or a newline
32 =begin[ \t]+(?:test|testing)(?:-SETUP)? # ... when we find a =begin test or testing
33 .*? # ... and keep capturing
34 \n=end[ \t]+(?:test|testing)(?:-SETUP)? # ... until an =end tag
36 (?:\n|$) # ... at the end of file or a newline
37 ) # ... and stop capturing
43 while ( $self->{source} =~ m/$search/go ) {
46 # A hack to turn the SYNOPSIS into something Test::Inline
48 if ( $elt =~ s/=head1[ \t]+SYNOPSIS/=begin testing-SETUP\n\n{/ ) {
49 $elt .= "}\n\n=end testing-SETUP";
52 # It seems like search.cpan doesn't like a name with
53 # spaces after =begin. bleah, what a mess.
54 $elt =~ s/testing-SETUP/testing SETUP/g;
59 # If we have just one element it's a SYNOPSIS, so there's no
61 return unless @elements > 2;
63 if ( @elements && $self->{source} =~ /=head1 NAME\n\n(Moose::Cookbook\S+)/ ) {
64 unshift @elements, 'package ' . $1 . ';';
67 ( first {/^=/} @elements ) ? \@elements : '';
74 use base 'Test::Inline::Content::Default';
79 my $base = $self->SUPER::process(@_);
81 $base =~ s/(\$\| = 1;)/use Test::Fatal;\n$1/;