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