line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::CoverDb; |
2
|
2
|
|
|
2
|
|
1550
|
use Mojo::Base 'Mojolicious::Plugin', -signatures; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
18
|
|
3
|
2
|
|
|
2
|
|
9041
|
use Mojo::Collection 'c'; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
1153
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
1
|
96
|
sub register ($self, $app, $conf = {}) { |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
4
|
|
8
|
2
|
50
|
|
|
|
15
|
if ($app->mode eq 'development') { |
9
|
2
|
|
100
|
|
|
43
|
my $route = $conf->{route} // 'coverdb'; |
10
|
2
|
|
|
|
|
6
|
$route =~ s#/$##; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
50
|
|
|
8
|
my $dir = $conf->{dir} // 'cover_db'; |
13
|
2
|
|
|
|
|
4
|
$dir =~ s#/$##; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
11
|
my $r = $app->routes; |
16
|
2
|
|
|
|
|
33
|
$r = $r->under($route); |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
956
|
push @{$app->renderer->classes}, __PACKAGE__; |
|
2
|
|
|
|
|
12
|
|
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
5
|
$r->get('/' => sub ($c) { |
|
2
|
|
|
|
|
128128
|
|
|
2
|
|
|
|
|
7
|
|
21
|
2
|
100
|
|
|
|
74
|
if (-e "$dir/coverage.html") { |
22
|
1
|
|
|
|
|
22
|
return $c->reply->file(Mojo::File->new($dir, 'coverage.html')->to_abs); |
23
|
|
|
|
|
|
|
} |
24
|
1
|
|
|
|
|
150
|
my $files = c(glob("$dir/*.html"))->map(sub { $_ =~ s#$dir/##; return $_; }); |
|
1
|
|
|
|
|
61
|
|
|
1
|
|
|
|
|
7
|
|
25
|
1
|
|
|
|
|
18
|
$c->stash('files' => $files); |
26
|
1
|
|
|
|
|
23
|
$c->stash('dir' => $dir); |
27
|
1
|
|
|
|
|
17
|
$c->stash('route' => $route); |
28
|
1
|
|
|
|
|
17
|
$c->render(template => 'coverdb_index', layout => undef); |
29
|
2
|
|
|
|
|
49
|
}); |
30
|
2
|
|
|
2
|
|
5
|
$r->get('/#file' => sub ($c) { |
|
2
|
|
|
|
|
27883
|
|
|
2
|
|
|
|
|
6
|
|
31
|
2
|
|
|
|
|
11
|
my $file = Mojo::File->new($dir, $c->param('file')); |
32
|
|
|
|
|
|
|
|
33
|
2
|
50
|
|
|
|
114
|
return $c->reply->not_found unless -e $file; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
82
|
$c->reply->file($file->to_abs); |
36
|
2
|
|
|
|
|
409
|
})->name('coverdb_file'); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=encoding utf8 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Mojolicious::Plugin::CoverDb - Mojolicious Plugin |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Mojolicious |
51
|
|
|
|
|
|
|
$self->plugin('CoverDb'); |
52
|
|
|
|
|
|
|
$self->plugin('CoverDb' => { dir => 'cover_db', route => 'coverdb' }); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Mojolicious::Lite |
55
|
|
|
|
|
|
|
plugin 'CoverDb'; |
56
|
|
|
|
|
|
|
plugin 'CoverDb' => { dir => 'cover_db', route => 'coverdb' }; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
L is a L plugin to conveniently expose a C directory |
61
|
|
|
|
|
|
|
generated by L. You automatically get C when going to the exposed route (if |
62
|
|
|
|
|
|
|
the file exists, otherwise, you’get a list of the files). |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
As L is a development tool, the directory is only exposed if C is C. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 OPTIONS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
L supports the following options. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 dir |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The directory to expose. It may be an absolute path or a path relative to your mojolicious app’s directory. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Default is C. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 route |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The route to the exposed directory. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Default is C. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
L inherits all methods from |
85
|
|
|
|
|
|
|
L and implements the following new ones. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 register |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$plugin->register(Mojolicious->new); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Register plugin in L application. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 BUGS and SUPPORT |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The latest source code can be browsed and fetched at: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
https://framagit.org/fiat-tux/mojolicious/mojolicious-plugin-coverdb |
98
|
|
|
|
|
|
|
git clone https://framagit.org/fiat-tux/mojolicious/mojolicious-plugin-coverdb.git |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Bugs and feature requests will be tracked at: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
https://framagit.org/fiat-tux/mojolicious/mojolicious-plugin-coverdb/issues |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Luc DIDRY |
107
|
|
|
|
|
|
|
CPAN ID: LDIDRY |
108
|
|
|
|
|
|
|
ldidry@cpan.org |
109
|
|
|
|
|
|
|
https://fiat-tux.fr/ |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This program is free software; you can redistribute |
114
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The full text of the license can be found in the |
117
|
|
|
|
|
|
|
LICENSE file included with this module. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SEE ALSO |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L, L, L. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__DATA__ |