line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statocles::Plugin::AudioTag; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENE'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Change audio file anchors to audio elements |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.0201'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
831
|
use v5.20.0; |
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Statocles::Base 'Class'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
11
|
|
|
|
|
|
|
with 'Statocles::Plugin'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has file_type => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => Str, |
17
|
|
|
|
|
|
|
default => sub { 'mp3' }, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub audio_tag { |
22
|
1
|
|
|
1
|
1
|
1165526
|
my ($self, $page) = @_; |
23
|
1
|
50
|
|
|
|
22
|
if ($page->has_dom) { |
24
|
|
|
|
|
|
|
$page->dom->find('a[href$=.'. $self->file_type .']')->each(sub { |
25
|
1
|
|
|
1
|
|
4897
|
my ($el) = @_; |
26
|
1
|
|
|
|
|
8
|
my $replacement = sprintf '<audio controls><source type="audio/%s" src="%s"></audio>', |
27
|
|
|
|
|
|
|
$self->file_type, $el->attr('href'); |
28
|
1
|
|
|
|
|
29
|
$el->replace($replacement); |
29
|
1
|
|
|
|
|
28
|
}); |
30
|
|
|
|
|
|
|
} |
31
|
1
|
|
|
|
|
381
|
return $page; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub register { |
36
|
0
|
|
|
0
|
1
|
|
my ($self, $site) = @_; |
37
|
|
|
|
|
|
|
$site->on(build => sub { |
38
|
0
|
|
|
0
|
|
|
my ($event) = @_; |
39
|
0
|
|
|
|
|
|
for my $page ($event->pages->@*) { |
40
|
0
|
|
|
|
|
|
$page = $self->audio_tag($page); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
}); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=pod |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=encoding UTF-8 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Statocles::Plugin::AudioTag - Change audio file anchors to audio elements |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 VERSION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
version 0.0201 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# site.yml |
64
|
|
|
|
|
|
|
site: |
65
|
|
|
|
|
|
|
class: Statocles::Site |
66
|
|
|
|
|
|
|
args: |
67
|
|
|
|
|
|
|
plugins: |
68
|
|
|
|
|
|
|
audio_tag: |
69
|
|
|
|
|
|
|
$class: Statocles::Plugin::AudioTag |
70
|
|
|
|
|
|
|
$args: |
71
|
|
|
|
|
|
|
file_type: 'ogg' |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 DESCRIPTION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
C<Statocles::Plugin::AudioTag> changes audio file anchor elements to |
76
|
|
|
|
|
|
|
audio elements. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 file_type |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The file type to replace. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Default: C<mp3> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 METHODS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 audio_tag |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$page = $plugin->audio_tag($page); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Process the audio bits of a L<Statocles::Page>. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 register |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Register this plugin to install its event handlers. Called automatically. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SEE ALSO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L<Statocles> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L<Statocles::Plugin> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
L<https://ology.github.io/2020/12/06/making-a-statocles-plugin/> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AUTHOR |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Gene Boggs <gene@cpan.org> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Gene Boggs. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
115
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |