Skip Alien-Ditaa
[gitmo/Moose.git] / inc / ExtractInlineTests.pm
1 package inc::ExtractInlineTests;
2
3 use Moose;
4
5 with 'Dist::Zilla::Role::FileGatherer';
6
7 use File::Basename qw( basename );
8 use File::Find::Rule;
9 use File::Spec;
10 use File::Temp qw( tempdir );
11 use inc::MyInline;
12 use Test::Inline;
13
14 sub gather_files {
15     my $self = shift;
16     my $arg  = shift;
17
18     my $inline = Test::Inline->new(
19         verbose        => 0,
20         ExtractHandler => 'My::Extract',
21         ContentHandler => 'My::Content',
22         OutputHandler  => My::Output->new($self),
23     );
24
25     for my $pod (
26         File::Find::Rule->file->name(qr/\.pod$/)->in('lib/Moose/Cookbook') ) {
27         $inline->add($pod);
28     }
29
30     $inline->save;
31 }
32
33 {
34     package My::Output;
35
36     sub new {
37         my $class = shift;
38         my $dzil  = shift;
39
40         return bless { dzil => $dzil }, $class;
41     }
42
43     sub write {
44         my $self    = shift;
45         my $name    = shift;
46         my $content = shift;
47
48         $name =~ s/^moose_cookbook_//;
49
50         $self->{dzil}->add_file(
51             Dist::Zilla::File::InMemory->new(
52                 name    => "t/recipes/$name",
53                 content => $content,
54             )
55         );
56
57         return 1;
58     }
59 }
60
61 1;