File Coverage

blib/lib/Dist/Zilla/Plugin/Test/Map/Tube.pm
Criterion Covered Total %
statement 27 27 100.0
branch 2 4 50.0
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 33 37 89.1


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Test::Map::Tube;
2             $Dist::Zilla::Plugin::Test::Map::Tube::VERSION = '0.43';
3             $Dist::Zilla::Plugin::Test::Map::Tube::AUTHORITY = 'cpan:MANWAR';
4              
5             =head1 NAME
6              
7             Dist::Zilla::Plugin::Test::Map::Tube - Provides release test for Test::Map::Tube.
8              
9             =head1 VERSION
10              
11             version 0.43
12              
13             =cut
14              
15 2     2   3111175 use Moose;
  2         374986  
  2         14  
16             with 'Dist::Zilla::Role::FileGatherer';
17             with 'Dist::Zilla::Role::PrereqSource';
18              
19 2     2   12506 use Dist::Zilla::File::InMemory;
  2         408327  
  2         733  
20              
21             =head1 DESCRIPTION
22              
23             This is an extension of L<Dist::Zilla::Plugin::InlineFiles>, providing following
24             file:
25              
26             xt/release/map.t
27              
28             This test uses L<Test::Map::Tube> to check your map data and basic functions.When
29             L<Test::Map::Tube> v0.15 or above is installed then it can even test your routes.
30              
31             =head1 SYNOPSIS
32              
33             Just add the following line to your C<dist.ini> file.
34              
35             [Test::Map::Tube]
36              
37             Optionally you can also provide test routes in a plain text file as below:
38              
39             routes = path/to/routes.txt
40              
41             The routes file should be structured as below:
42              
43             Route Name|Start Station Name|End Station Name|Start Station Name,via-station-name-1,via-station-name-2,End Station Name
44             ....
45             ....
46             ....
47              
48             =cut
49              
50             our $MIN_VER = '0.56';
51             has 'routes' => (is => 'ro', required => 0);
52              
53             sub register_prereqs {
54 1     1 0 4389 my ($self) = @_;
55              
56 1         25 $self->zilla->register_prereqs(
57             {
58             type => 'requires',
59             phase => 'develop',
60             },
61             'Test::Map::Tube' => $MIN_VER,
62             );
63             }
64              
65             sub gather_files {
66 1     1 0 59030 my ($self) = @_;
67              
68 1         31 my $routes_file = $self->routes;
69 1         4 my $file_name = "xt/release/map.t";
70 1         2 my $min_tests = 3;
71              
72 1 50       4 if (defined $routes_file) {
73 1         2 $min_tests += 1;
74             }
75              
76 1         5 my $file_content = sprintf("
77             #!perl
78              
79             # This file was automatically generated by Dist::Zilla::Plugin::Test::Map::Tube v%s.
80              
81             use strict; use warnings;
82             use utf8;\n",
83             $Dist::Zilla::Plugin::Test::Map::Tube::VERSION);
84 1         4 $file_content .= lc('U').lc('S').lc('E'). " Test::More;\n";
85 1         5 $file_content .= sprintf("
86             my \$min_tmt = '%s';
87             eval \"use Test::Map::Tube \$min_tmt tests => %s\";
88             plan skip_all => \"Test::Map::Tube \$min_tmt required\" if \$\@;", $MIN_VER, $min_tests);
89              
90 1         25 my $map_module = $self->zilla->name;
91 1         32 $map_module =~ s/\-/\:\:/g;
92 1         6 $file_content .=
93             sprintf("\n\nuse %s;\n\nmy \$map = new_ok('%s');\n\nSKIP: {\n\nok_map(\$map) or skip 'no map data found', 2;\n\nok_map_functions(\$map);\n\n",
94             $map_module, $map_module);
95              
96 1 50       5 if (defined $routes_file) {
97 1         6 $file_content .=
98             sprintf("open(IN, '<:encoding(UTF-8)', %s) or die \"Can't open routes file: \$\!\\n\"; my \@routes = <IN>; close(IN);\n\n",
99             $routes_file);
100 1         4 $file_content .= q{ok_map_routes($map, \@routes);};
101 1         2 $file_content .= "\n\n";
102             }
103              
104 1         3 $file_content .= "}\n\n";
105              
106 1         6 $self->log(["Adding %s ...", $file_name]);
107 1         599 $self->add_file(
108             Dist::Zilla::File::InMemory->new(
109             {
110             name => $file_name,
111             content => $file_content,
112             })
113             );
114             }
115              
116             =head1 AUTHOR
117              
118             Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
119              
120             =head1 REPOSITORY
121              
122             L<https://github.com/manwar/Dist-Zilla-Plugin-Test-Map-Tube>
123              
124             =head1 SEE ALSO
125              
126             =over 4
127              
128             =item L<Map::Tube>
129              
130             =item L<Test::Map::Tube>
131              
132             =back
133              
134             =head1 BUGS
135              
136             Please report any bugs / feature requests to C<bug-dist-zilla-plugin-test-map-tube at rt.cpan.org>,
137             or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dist-Zilla-Plugin-Test-Map-Tube>.
138             I will be notified, and then you'll automatically be notified of progress on your
139             bug as I make changes.
140              
141             =head1 SUPPORT
142              
143             You can find documentation for this module with the perldoc command.
144              
145             perldoc Dist::Zilla::Plugin::Test::Map::Tube
146              
147             You can also look for information at:
148              
149             =over 4
150              
151             =item * RT: CPAN's request tracker (report bugs here)
152              
153             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dist-Zilla-Plugin=Test-Map-Tube>
154              
155             =item * AnnoCPAN: Annotated CPAN documentation
156              
157             L<http://annocpan.org/dist/Dist-Zilla-Plugin=Test-Map-Tube>
158              
159             =item * CPAN Ratings
160              
161             L<http://cpanratings.perl.org/d/Dist-Zilla-Plugin-Test-Map-Tube>
162              
163             =item * Search CPAN
164              
165             L<http://search.cpan.org/dist/Dist-Zilla-Plugin-Test-Map-Tube/>
166              
167             =back
168              
169             =head1 LICENSE AND COPYRIGHT
170              
171             Copyright (C) 2015 - 2019 Mohammad S Anwar.
172              
173             This program is free software; you can redistribute it and/or modify it under
174             the terms of the the Artistic License (2.0). You may obtain a copy of the full
175             license at:
176              
177             L<http://www.perlfoundation.org/artistic_license_2_0>
178              
179             Any use, modification, and distribution of the Standard or Modified Versions is
180             governed by this Artistic License.By using, modifying or distributing the Package,
181             you accept this license. Do not use, modify, or distribute the Package, if you do
182             not accept this license.
183              
184             If your Modified Version has been derived from a Modified Version made by someone
185             other than you,you are nevertheless required to ensure that your Modified Version
186             complies with the requirements of this license.
187              
188             This license does not grant you the right to use any trademark, service mark,
189             tradename, or logo of the Copyright Holder.
190              
191             This license includes the non-exclusive, worldwide, free-of-charge patent license
192             to make, have made, use, offer to sell, sell, import and otherwise transfer the
193             Package with respect to any patent claims licensable by the Copyright Holder that
194             are necessarily infringed by the Package. If you institute patent litigation
195             (including a cross-claim or counterclaim) against any party alleging that the
196             Package constitutes direct or contributory patent infringement,then this Artistic
197             License to you shall terminate on the date that such litigation is filed.
198              
199             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
200             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
201             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
202             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
203             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
204             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
205             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
206              
207             =cut
208              
209             __PACKAGE__->meta->make_immutable;
210              
211             1; # End of Dist::Zilla::Plugin::Test::Map::Tube