/
README
121 lines (89 loc) · 3.02 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Acme::CommentChanger version 0.01
========================
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
Test::More
PPI
NAME
Acme::CommentChanger - change your source comment.
SYNOPSYS
package YourModule;
use strict;
use base qw( Acme::CommentChanger );
sub handler_token {
return sub {
my ( $self, $token ) = @_; # $token is PPI::Token::Comment
my $content = $token->content;
#
# ....
#
$token->set_content( $content );
}
}
#
package main;
my $changer = YourModule->new;
my $code = 'your source code';
my $changed_code = $changer->change_code( $code );
DESCRIPTION
A source code comments (#headed) changer.
You can rewrite handler methods to change comments simply.
METHODS
new
$changer = $class->new( [ $hashref ] );
A constructor. It can take an optional hash reference.
change_code
$changer->change_code( $code [, $hashref] );
Takes a code and returns a changed code. It can take an optional hash
reference.
handle_token
It takes a PPI::Document object, an init handler, a token handler, a
finish handler and an optional hash reference.
This method is called by "change_code" internally. In many cases, you
don't need to call it directly.
HANDLERS
handler_init
Called before handling comment tokens in "handle_token" method. It
return a subroutine reference which takes three arguments. The first
argument is an object itself. Second is a PPI::Document object. Last one
is a optional hash reference.
sub handler_init {
return sub {
my ( $self, $document, $opt ) = @_;
# ... your code
}
}
handler_token
Called after "handler_init". It returns a subroutine reference which
takes two arguments. The first argument is an object itself. Second is a
PPI::Token::Comment object.
sub handler_token {
return sub {
my ( $self, $token ) = @_;
my $content = $token->content; # comment text
# ... you code
$token->set_content( $content ); # set a new text
}
}
handler_finish
Called after all comment tokens are handled. It return a subroutine
reference which takes three arguments. The first argument is an object
itself. Second is a PPI::Document object. This subroutine reference must
return a PPI::Document content.
sub handler_finish {
sub {
my ( $self, $document ) = @_;
return $document->content;
};
}
SEE ALSO
Acme::MorseComments, PPI
COPYRIGHT AND LICENSE
Copyright (C) 2009 Makamaka Hannyaharamitu.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.