| 1 | 2 | ▶ | use 5.10.0; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | package Dist::Zilla::Plugin::Stenciller::MojoliciousTests; | ||
| 5 | |||
| 6 | # ABSTRACT: Create Mojolicious tests from text files parsed with Stenciller | ||
| 7 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |
| 8 | 2 | our $VERSION = '0.0200'; | |
| 9 | |||
| 10 | 2 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 2 | with 'Dist::Zilla::Role::FileGatherer'; | |
| 12 | 2 | ▶ | use Stenciller; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 2 | ▶ | use Types::Stenciller -types; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 2 | ▶ | use Types::Standard qw/Str/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 2 | ▶ | use Types::Path::Tiny qw/AbsFile Dir Path/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 2 | ▶ | use Path::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 2 | ▶ | use Dist::Zilla::File::InMemory; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 2 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 2 | has source_directory => ( | |
| 21 | is => 'ro', | ||
| 22 | isa => Dir, | ||
| 23 | coerce => 1, | ||
| 24 | default => 'examples/source', | ||
| 25 | ); | ||
| 26 | 2 | has file_pattern => ( | |
| 27 | is => 'ro', | ||
| 28 | isa => Str, | ||
| 29 | default => '.+\.stencil', | ||
| 30 | ); | ||
| 31 | 2 | has output_directory => ( | |
| 32 | is => 'ro', | ||
| 33 | isa => Path, | ||
| 34 | coerce => 1, | ||
| 35 | default => 't', | ||
| 36 | ); | ||
| 37 | has template_file => ( | ||
| 38 | is => 'ro', | ||
| 39 | isa => AbsFile, | ||
| 40 | lazy => 1, | ||
| 41 | coerce => 1, | ||
| 42 | 0 | ▶ | default => sub { shift->source_directory->child('template.test')->absolute }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 43 | 2 | ); | |
| 44 | |||
| 45 | 1 | ▶ | sub gather_files { |
|
Subroutine
gather_files: called CC=2 SCAR=6.9
Pod
undocumented
| |||
| 46 | 1 | my $self = shift; | |
| 47 | |||
| 48 | 1 | my $template = $self->template_file->slurp_utf8; | |
| 49 | 1 | my @source_files = $self->source_directory->children(qr{^@{[ $self->file_pattern ]}$}); | |
| 50 | |||
| 51 | 1 | $self->log('Generating tests from stencils'); | |
| 52 | |||
| 53 | 1 | foreach my $file (@source_files) { | |
| 54 | 1 | my $contents = Stenciller->new(filepath => $file->stringify)->transform( | |
| 55 | plugin_name => 'ToMojoliciousTest', | ||
| 56 | transform_args => { | ||
| 57 | require_in_extra => { | ||
| 58 | key => 'is_test', | ||
| 59 | value => 1, | ||
| 60 | default => 1 | ||
| 61 | }, | ||
| 62 | }, | ||
| 63 | constructor_args => { | ||
| 64 | template => $self->template_file, | ||
| 65 | }, | ||
| 66 | ); | ||
| 67 | |||
| 68 | 1 | my $new_filename = $file->basename(qr/\.[^.]+$/) . '.t'; | |
| 69 | 1 | $self->log("Generated $new_filename"); | |
| 70 | |||
| 71 | 1 | my $generated_file = Dist::Zilla::File::InMemory->new( | |
| 72 | name => path($self->output_directory, $new_filename)->stringify, | ||
| 73 | content => $contents, | ||
| 74 | ); | ||
| 75 | 1 | $self->add_file($generated_file); | |
| 76 | |||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | 2 | __PACKAGE__->meta->make_immutable; | |
| 81 | |||
| 82 | 2 | 1; | |
| 83 | |||
| 84 | __END__ | ||