line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pod::Trac; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
48730
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
5
|
2
|
|
|
2
|
|
18
|
use Carp; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
190
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
3031
|
use File::Util; |
|
2
|
|
|
|
|
50248
|
|
|
2
|
|
|
|
|
15
|
|
8
|
2
|
|
|
2
|
|
1989
|
use URI::Escape; |
|
2
|
|
|
|
|
2858
|
|
|
2
|
|
|
|
|
133
|
|
9
|
2
|
|
|
2
|
|
3265
|
use HTTP::Request::Common qw(POST); |
|
2
|
|
|
|
|
70821
|
|
|
2
|
|
|
|
|
182
|
|
10
|
2
|
|
|
2
|
|
4982
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
69923
|
|
|
2
|
|
|
|
|
79
|
|
11
|
2
|
|
|
2
|
|
3003
|
use HTTP::Cookies; |
|
2
|
|
|
|
|
16953
|
|
|
2
|
|
|
|
|
70
|
|
12
|
2
|
|
|
2
|
|
2084
|
use Pod::Simple::Wiki; |
|
2
|
|
|
|
|
78654
|
|
|
2
|
|
|
|
|
84
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
37
|
use base qw( Class::Accessor::Fast ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2038
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(form_token pod_url pod_rev) ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Pod::Trac - Convert a POD to trac's wiki syntax and add it to the trac |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 VERSION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This document describes Pod::Trac version 0.0.1 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Pod::Trac; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $trac = Pod::Trac->new({url => "http", login => "mylogin", passwd => "mypass"}); |
34
|
|
|
|
|
|
|
$trac->from_file({file => "myfile.pm"}); |
35
|
|
|
|
|
|
|
# or |
36
|
|
|
|
|
|
|
$trac->from_path({path => "/my/path/", file_filter => "pm"}); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
see pod2trac.pl in the example directory |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Extract POD from your sources, convert them to the trac's wiki syntax, and create or update the |
43
|
|
|
|
|
|
|
page with the new document |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head3 init |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
create a LWP Object. |
52
|
|
|
|
|
|
|
Log in the trac wiki, and store the cookie. |
53
|
|
|
|
|
|
|
get the trac_form_token |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head3 generate |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Convert the POD to the wiki syntax. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head3 write_to_trac |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
send the POD to the trac |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
set $self->pod_rev to the revision of the current page |
64
|
|
|
|
|
|
|
set $self->pod_url to the url of the page created/updated |
65
|
|
|
|
|
|
|
push in $self->{created_path} the $self->pod_rev and $self->pod_url |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head3 from_file |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Get a filename and convert the pod in this file |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head3 from_path |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Look in a directory, for all the pods and send them to the trac. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub init { |
78
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
79
|
0
|
|
|
|
|
|
$self->{ ua } = LWP::UserAgent->new; |
80
|
0
|
|
|
|
|
|
$self->{ ua }->cookie_jar( {} ); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( GET => $self->{ trac_url } . "/login" ); |
83
|
0
|
|
|
|
|
|
$req->authorization_basic( $self->{ login }, $self->{ passwd } ); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $response = $self->{ ua }->request( $req ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# are we logged in ? |
88
|
0
|
0
|
|
|
|
|
if ( !$response->is_success ) { |
89
|
0
|
|
|
|
|
|
croak( "Can't login on this trac, check your login" ); |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
my $cookie = $response->request->headers->{ cookie }; |
92
|
0
|
|
|
|
|
|
$cookie =~ /trac_form_token=(.*);/; |
93
|
0
|
|
|
|
|
|
$self->form_token( $1 ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub generate { |
97
|
0
|
|
|
0
|
1
|
|
my ( $self, $file ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my ( $parser, $wiki ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# convert the pod to wiki syntax |
102
|
0
|
|
|
|
|
|
$parser = Pod::Simple::Wiki->new( 'moinmoin' ); |
103
|
0
|
|
|
|
|
|
$parser->output_string( \$wiki ); |
104
|
0
|
|
|
|
|
|
$parser->parse_file( $file ); |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
return if length $wiki < 1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# send data to trac |
109
|
0
|
|
|
|
|
|
$self->write_to_trac( $wiki, $file ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub write_to_trac { |
113
|
0
|
|
|
0
|
1
|
|
my ( $self, $poddata, $podname ) = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$poddata = uri_escape( $poddata ); |
116
|
0
|
|
|
|
|
|
$podname =~ s/(\.\.\/)//g; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$self->pod_url( $self->{ trac_url } . "/wiki/" . $podname ); |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$self->pod_rev( 0 ); |
121
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( GET => $self->pod_url ); |
122
|
0
|
|
|
|
|
|
my $response = $self->{ ua }->request( $req ); |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
if ( $response->is_success ) { |
125
|
0
|
0
|
|
|
|
|
if ( $response->content |
126
|
|
|
|
|
|
|
=~ /<input type="hidden" name="version" value="(\d+?)" \/>/ ) |
127
|
|
|
|
|
|
|
{ |
128
|
0
|
|
|
|
|
|
$self->pod_rev( $1 ); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
$req = HTTP::Request->new( POST => $self->pod_url ); |
133
|
0
|
|
|
|
|
|
$req->content_type( 'application/x-www-form-urlencoded' ); |
134
|
0
|
|
|
|
|
|
$req->content( "__FORM_TOKEN=" |
135
|
|
|
|
|
|
|
. $self->form_token |
136
|
|
|
|
|
|
|
. "&action=edit&version=" |
137
|
|
|
|
|
|
|
. $self->pod_rev |
138
|
|
|
|
|
|
|
. "&text=" |
139
|
|
|
|
|
|
|
. $poddata |
140
|
|
|
|
|
|
|
. "&save=Submit+changes" ); |
141
|
0
|
|
|
|
|
|
$response = $self->{ ua }->request( $req ); |
142
|
0
|
|
|
|
|
|
push @{ $self->{ created_path } }, |
|
0
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
{ pod_url => $self->pod_url, pod_rev => $self->pod_rev }; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub from_file { |
147
|
0
|
|
|
0
|
1
|
|
my ( $self, $params ) = @_; |
148
|
|
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
|
croak( "Please give me a file" ) unless defined $$params{ 'file' }; |
150
|
0
|
|
|
|
|
|
$self->init(); |
151
|
0
|
|
|
|
|
|
$self->generate( $$params{ file } ); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub from_path { |
156
|
0
|
|
|
0
|
1
|
|
my ( $self, $params ) = @_; |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
|
croak( "Please give me a path" ) unless defined $$params{ 'path' }; |
159
|
0
|
|
|
|
|
|
$self->init(); |
160
|
0
|
|
|
|
|
|
my $f = File::Util->new(); |
161
|
0
|
|
|
|
|
|
my @files = $f->list_dir( $$params{ 'path' }, |
162
|
|
|
|
|
|
|
qw/--files-only --recurse --no-fsdots/ ); |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
foreach my $file ( @files ) { |
165
|
0
|
0
|
|
|
|
|
if ( defined $$params{ 'filter' } ) { |
166
|
0
|
0
|
|
|
|
|
if (grep { $file =~ /\.$_$/} @{$$params{filter}}){ |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
$self->generate( $file ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |
174
|
|
|
|
|
|
|
__END__ |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
No bugs have been reported. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
181
|
|
|
|
|
|
|
C<bug-pod-trac@rt.cpan.org>, or through the web interface at |
182
|
|
|
|
|
|
|
L<http://rt.cpan.org>. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
franck cuny C<< <franck.cuny@gmail.com> >> |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 LICENCE AND COPYRIGHT |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Copyright (c) 2007, franck cuny C<< <franck.cuny@gmail.com> >>. All rights reserved. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
195
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. See L<perlartistic>. |