1 package inc::ExtractInlineTests;
5 with 'Dist::Zilla::Role::FileGatherer';
7 use File::Basename qw( basename );
10 use File::Temp qw( tempdir );
17 my $inline = Test::Inline->new(
19 ExtractHandler => 'My::Extract',
20 ContentHandler => 'My::Content',
21 OutputHandler => My::Output->new($self),
25 File::Find::Rule->file->name(qr/\.pod$/)->in('lib/Moose/Cookbook') ) {
35 use base 'Test::Inline::Extract';
37 # This extracts the SYNOPSIS in addition to code specifically
40 (?:^|\n) # After the beginning of the string, or a newline
41 ( # ... start capturing
43 package\s+ # A package
44 [^\W\d]\w*(?:(?:\'|::)[^\W\d]\w*)* # ... with a name
45 \s*; # And a statement terminator
47 =head1[ \t]+SYNOPSIS\n
51 =for[ \t]+example[ \t]+begin\n # ... when we find a =for example begin
52 .*? # ... and keep capturing
53 \n=for[ \t]+example[ \t]+end\s*? # ... until the =for example end
54 (?:\n|$) # ... at the end of file or a newline
56 =begin[ \t]+(?:test|testing)(?:-SETUP)? # ... when we find a =begin test or testing
57 .*? # ... and keep capturing
58 \n=end[ \t]+(?:test|testing)(?:-SETUP)? # ... until an =end tag
60 (?:\n|$) # ... at the end of file or a newline
61 ) # ... and stop capturing
67 while ( $self->{source} =~ m/$search/go ) {
70 # A hack to turn the SYNOPSIS into something Test::Inline
72 if ( $elt =~ s/=head1[ \t]+SYNOPSIS/=begin testing-SETUP\n\n{/ ) {
73 $elt .= "}\n\n=end testing-SETUP";
76 # It seems like search.cpan doesn't like a name with
77 # spaces after =begin. bleah, what a mess.
78 $elt =~ s/testing-SETUP/testing SETUP/g;
83 # If we have just one element it's a SYNOPSIS, so there's no
85 return unless @elements > 2;
87 if ( @elements && $self->{source} =~ /=head1 NAME\n\n(Moose::Cookbook\S+)/ ) {
88 unshift @elements, 'package ' . $1 . ';';
91 ( List::Util::first {/^=/} @elements ) ? \@elements : '';
98 use base 'Test::Inline::Content::Default';
103 my $base = $self->SUPER::process(@_);
105 $base =~ s/(\$\| = 1;)/use Test::Fatal;\n$1/;
118 return bless { dzil => $dzil }, $class;
126 $name =~ s/^moose_cookbook_//;
128 $self->{dzil}->add_file(
129 Dist::Zilla::File::InMemory->new(
130 name => "t/002_recipes/$name",