line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Tidy::Sweetened::Pluggable; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Simple object to facilitate a pluggable filter architecture |
4
|
|
|
|
|
|
|
|
5
|
15
|
|
|
15
|
|
120
|
use strict; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
479
|
|
6
|
15
|
|
|
15
|
|
118
|
use warnings; |
|
15
|
|
|
|
|
38
|
|
|
15
|
|
|
|
|
4718
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.20'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
15
|
|
|
15
|
0
|
47
|
my ( $class, %args ) = @_; |
12
|
15
|
|
|
|
|
88
|
return bless {%args}, $class; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
413
|
|
100
|
413
|
0
|
1900
|
sub filters { return ( $_[0]->{filters} ||= [] ) } |
16
|
|
|
|
|
|
|
|
17
|
2834
|
|
50
|
2834
|
0
|
10351
|
sub args { return ( $_[0]->{args} ||= {} ) } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub add_filter { |
20
|
195
|
|
|
195
|
0
|
344
|
my $self = shift; |
21
|
195
|
|
|
|
|
277
|
push @{ $self->filters }, @_; |
|
195
|
|
|
|
|
333
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub prefilter { |
25
|
109
|
|
|
109
|
0
|
396
|
my ( $self, $code ) = @_; |
26
|
109
|
|
|
|
|
222
|
for my $filter ( @{ $self->filters } ) { |
|
109
|
|
|
|
|
308
|
|
27
|
1417
|
|
|
|
|
3381
|
$code = $filter->prefilter($code, $self->args); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# warn "After prefilter, before tidy\n"; |
31
|
|
|
|
|
|
|
# warn $code; |
32
|
|
|
|
|
|
|
|
33
|
109
|
|
|
|
|
399
|
return $code; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub postfilter { |
37
|
109
|
|
|
109
|
0
|
367
|
my ( $self, $code ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# warn "After tidy, before postfilter\n"; |
40
|
|
|
|
|
|
|
# warn $code; |
41
|
|
|
|
|
|
|
|
42
|
109
|
|
|
|
|
214
|
for my $filter ( @{ $self->filters } ) { |
|
109
|
|
|
|
|
309
|
|
43
|
1417
|
|
|
|
|
3372
|
$code = $filter->postfilter($code, $self->args); |
44
|
|
|
|
|
|
|
} |
45
|
109
|
|
|
|
|
389
|
return $code; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub add_args { |
49
|
109
|
|
|
109
|
0
|
314
|
my ( $self, $args ) = @_; |
50
|
109
|
|
|
|
|
394
|
my ( $body_parts, $msg ) = Perl::Tidy::parse_args($args); |
51
|
|
|
|
|
|
|
$self->{args} = |
52
|
109
|
|
|
|
|
15141
|
{ map { my ( $k, $v ) = split /=/, $_, 2; ( $k => $v ) } @$body_parts }; |
|
445
|
|
|
|
|
1164
|
|
|
445
|
|
|
|
|
1682
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=pod |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Perl::Tidy::Sweetened::Pluggable - Simple object to facilitate a pluggable filter architecture |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 VERSION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
version 1.20 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
our $plugins = Perl::Tidy::Sweetened::Pluggable->new(); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$plugins->add_filter( |
74
|
|
|
|
|
|
|
Perl::Tidy::Sweetened::Keyword::SubSignature->new( |
75
|
|
|
|
|
|
|
keyword => 'method', |
76
|
|
|
|
|
|
|
marker => 'METHOD', |
77
|
|
|
|
|
|
|
) ); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$plugins->prefilter( $code ); |
80
|
|
|
|
|
|
|
$plugins->postfilter( $code ); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 DESCRIPTION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Builds a pluggable, chainable list of filters. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Mark Grimes <mgrimes@cpan.org> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SOURCE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Source repository is at L<https://github.com/mvgrimes/Perl-Tidy-Sweetened>. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 BUGS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://github.com/mvgrimes/Perl-Tidy-Sweetened/issues> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
99
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
100
|
|
|
|
|
|
|
feature. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This software is copyright (c) 2023 by Mark Grimes <mgrimes@cpan.org>. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
107
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |