File Coverage

blib/lib/Dist/Zilla/Plugin/Test/CreateFromMojoTemplates.pm
Criterion Covered Total %
statement 24 36 66.6
branch n/a
condition n/a
subroutine 8 9 88.8
pod 0 1 0.0
total 32 46 69.5


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Test::CreateFromMojoTemplates;
2              
3 1     1   16844 use strict;
  1         2  
  1         37  
4 1     1   10 use 5.10.1;
  1         3  
  1         45  
5             our $VERSION = '0.06';
6              
7 1     1   611 use Moose;
  1         394530  
  1         12  
8 1     1   6631 use File::Find::Rule;
  1         7202  
  1         10  
9 1     1   608 use namespace::sweep;
  1         9437  
  1         8  
10 1     1   733 use Path::Tiny;
  1         12638  
  1         98  
11 1     1   649 use MojoX::CustomTemplateFileParser;
  1         76876  
  1         45  
12              
13 1     1   627 use Dist::Zilla::File::InMemory;
  1         256401  
  1         421  
14             with 'Dist::Zilla::Role::FileGatherer';
15              
16             has directory => (
17             is => 'ro',
18             isa => 'Str',
19             default => sub { 'examples/source/' },
20             );
21             has filepattern => (
22             is => 'ro',
23             isa => 'Str',
24             default => sub { '^\w+-\d+\.mojo$' },
25             );
26              
27             sub gather_files {
28 0     0 0   my $self = shift;
29 0           my $arg = shift;
30              
31 0           my $test_template_path = (File::Find::Rule->file->name('template.test')->in($self->directory))[0];
32 0           my $test_template = path($test_template_path)->slurp;
33              
34 0           my @paths = File::Find::Rule->file->name(qr/@{[ $self->filepattern ]}/)->in($self->directory);
  0            
35 0           foreach my $path (@paths) {
36              
37 0           my $contents = MojoX::CustomTemplateFileParser->new(path => path($path)->absolute->canonpath, output => ['Test'])->to_test;
38 0           my $filename = path($path)->basename(qr{\.[^.]+});
39              
40 0           my $file = Dist::Zilla::File::InMemory->new(
41             name => "t/$filename.t",
42             content => $test_template . $contents,
43             );
44 0           $self->add_file($file);
45              
46             }
47              
48 0           return;
49             }
50              
51             __PACKAGE__->meta->make_immutable;
52              
53             1;
54              
55             __END__
56              
57             =encoding utf-8
58              
59             =head1 NAME
60              
61             Dist::Zilla::Plugin::Test::CreateFromMojoTemplates - Create tests from custom L<Mojolicious> templates
62              
63             =for html <p><a style="float: left;" href="https://travis-ci.org/Csson/p5-dist-zilla-plugin-test-createfrommojotemplate"><img src="https://travis-ci.org/Csson/p5-dist-zilla-plugin-test-createfrommojotemplate.svg?branch=master">&nbsp;</a>
64              
65             =head1 SYNOPSIS
66              
67             ; In dist.ini
68             [Test::CreateFromMojoTemplates]
69             directory = examples/source
70             filepattern = ^\w+-\d+\.mojo$
71              
72             =head1 DESCRIPTION
73              
74             Dist::Zilla::Plugin::Test::CreateFromMojoTemplates creates tests by parsing a custom file format
75             containg Mojolicious templates and the expected rendering. See L<MojoX::CustomTemplateFileParser> for details.
76              
77             It looks for files in a given C<directory> (by default C<examples/source>) that matches C<filepattern> (by default C<^\w+-\d+\.mojo$>).
78              
79             If you have many files you can also create a C<template.test> (currently hardcoded) file. Its content will be placed at the top of all created test files.
80              
81             =head1 AUTHOR
82              
83             Erik Carlsson E<lt>info@code301.comE<gt>
84              
85             =head1 COPYRIGHT
86              
87             Copyright 2014- Erik Carlsson
88              
89             =head1 LICENSE
90              
91             This library is free software; you can redistribute it and/or modify
92             it under the same terms as Perl itself.
93              
94             =head1 SEE ALSO
95              
96             =cut