line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
2480175
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
2
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
91
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::Stenciller::MojoliciousTests { |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.0100'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: Create Mojolicious tests from text files parsed with Stenciller |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
9
|
use Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
13
|
|
10
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::FileGatherer'; |
11
|
1
|
|
|
1
|
|
9063
|
use Stenciller; |
|
1
|
|
|
|
|
1382934
|
|
|
1
|
|
|
|
|
50
|
|
12
|
1
|
|
|
1
|
|
9
|
use Types::Stenciller -types; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
13
|
1
|
|
|
1
|
|
6138
|
use Path::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
14
|
1
|
|
|
1
|
|
965
|
use Dist::Zilla::File::InMemory; |
|
1
|
|
|
|
|
89094
|
|
|
1
|
|
|
|
|
579
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has source_directory => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
isa => Dir, |
19
|
|
|
|
|
|
|
coerce => 1, |
20
|
|
|
|
|
|
|
default => 'examples/source', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
has file_pattern => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => Str, |
25
|
|
|
|
|
|
|
default => '.+\.stencil', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
has output_directory => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => Path, |
30
|
|
|
|
|
|
|
coerce => 1, |
31
|
|
|
|
|
|
|
default => 't', |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
has template_file => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
isa => AbsFile, |
36
|
|
|
|
|
|
|
lazy => 1, |
37
|
|
|
|
|
|
|
coerce => 1, |
38
|
|
|
|
|
|
|
default => sub { shift->source_directory->child('template.test')->absolute }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub gather_files { |
42
|
1
|
|
|
1
|
0
|
700611
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
60
|
my $template = $self->template_file->slurp_utf8; |
45
|
1
|
|
|
|
|
294
|
my @source_files = $self->source_directory->children(qr{^@{[ $self->file_pattern ]}$}); |
|
1
|
|
|
|
|
78
|
|
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
151
|
$self->log('Generating tests from stencils'); |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
321
|
foreach my $file (@source_files) { |
50
|
1
|
|
|
|
|
9
|
my $contents = Stenciller->new(filepath => $file->stringify)->transform( |
51
|
|
|
|
|
|
|
plugin_name => 'ToMojoliciousTest', |
52
|
|
|
|
|
|
|
transform_args => { |
53
|
|
|
|
|
|
|
require_in_extra => { |
54
|
|
|
|
|
|
|
key => 'is_test', |
55
|
|
|
|
|
|
|
value => 1, |
56
|
|
|
|
|
|
|
default => 1 |
57
|
|
|
|
|
|
|
}, |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
constructor_args => { |
60
|
|
|
|
|
|
|
template => $self->template_file, |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
76295
|
my $new_filename = $file->basename(qr/\.[^.]+$/) . '.t'; |
65
|
1
|
|
|
|
|
323
|
$self->log("Generated $new_filename"); |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
467
|
my $generated_file = Dist::Zilla::File::InMemory->new( |
68
|
|
|
|
|
|
|
name => path($self->output_directory, $new_filename)->stringify, |
69
|
|
|
|
|
|
|
content => $contents, |
70
|
|
|
|
|
|
|
); |
71
|
1
|
|
|
|
|
435
|
$self->add_file($generated_file); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=pod |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=encoding UTF-8 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Dist::Zilla::Plugin::Stenciller::MojoliciousTests - Create Mojolicious tests from text files parsed with Stenciller |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=begin HTML |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
<p><img src="https://img.shields.io/badge/perl-5.14-brightgreen.svg" alt="Requires Perl 5.14" /> <a href="https://travis-ci.org/Csson/p5-Dist-Zilla-Plugin-Stenciller-MojoliciousTests"><img src="https://api.travis-ci.org/Csson/p5-Dist-Zilla-Plugin-Stenciller-MojoliciousTests.svg?branch=master" alt="Travis status" /></a></p> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=end HTML |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=begin markdown |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
![Requires Perl 5.14](https://img.shields.io/badge/perl-5.14-brightgreen.svg) [![Travis status](https://api.travis-ci.org/Csson/p5-Dist-Zilla-Plugin-Stenciller-MojoliciousTests.svg?branch=master)](https://travis-ci.org/Csson/p5-Dist-Zilla-Plugin-Stenciller-MojoliciousTests) |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=end markdown |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 VERSION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Version 0.0100, released 2015-11-23. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SYNOPSIS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
; in dist.ini |
112
|
|
|
|
|
|
|
; these are the defaults: |
113
|
|
|
|
|
|
|
[Stenciller::MojoliciousTests] |
114
|
|
|
|
|
|
|
source_directory = examples/source |
115
|
|
|
|
|
|
|
file_pattern = .+\.stencil |
116
|
|
|
|
|
|
|
template_file = examples/source/template.test |
117
|
|
|
|
|
|
|
output_directory = t |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 DESCRIPTION |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Dist::Zilla::Plugin::Stenciller::MojoliciousTests uses L<Stenciller> and L<Stenciller::Plugin::ToMojoliciousTest> to turn |
122
|
|
|
|
|
|
|
stencil files in C<source_directory> (that matches the C<file_pattern>) into |
123
|
|
|
|
|
|
|
test files in C<output_directory> by applying the C<template_file>. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This L<Dist::Zilla> plugin does the C<FileGatherer> role. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 source_directory |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Path to where the stencil files are. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 output_directory |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Path to where the generated files are saved. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 file_pattern |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This is put inside a regular expression (with start and end anchors) to find stencil files in the C<source_directory>. The output files |
140
|
|
|
|
|
|
|
will have the same basename, but the suffix is replaced by C<t>. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 template_file |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
The template file should contain use statements and such. The transformed contents returned from L<Stenciller::Plugin::ToMojoliciousTest> will be placed after |
145
|
|
|
|
|
|
|
the contents of C<template_file>. The template file is applied to each stencil file, so the number of generated test files is equal |
146
|
|
|
|
|
|
|
to the number of stencil files. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SEE ALSO |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=over 4 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L<Stenciller> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L<Stenciller::Plugin::ToMojoliciousTest> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SOURCE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L<https://github.com/Csson/p5-Dist-Zilla-Plugin-Stenciller-MojoliciousTests> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 HOMEPAGE |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L<https://metacpan.org/release/Dist-Zilla-Plugin-Stenciller-MojoliciousTests> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 AUTHOR |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Erik Carlsson <info@code301.com> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Erik Carlsson. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
179
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |