line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Trynt::PDF::File; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
WebService::Trynt::PDF::File - Interface to manage information about the file created with WebService::Trynt::PDF |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Version 0.01 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
16
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
17
|
1
|
|
|
1
|
|
631
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use File::Temp; |
19
|
|
|
|
|
|
|
use File::Copy; |
20
|
|
|
|
|
|
|
use LWP::UserAgent; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
WebService::Trynt::PDF is an interface for Trynt Web Services, so you can convert an URL into a PDF file. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use WebService::Trynt::PDF; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $trynt_ws = WebService::Trynt::PDF->new( url => "http://www.cnn.com", cache_flush => 0); |
29
|
|
|
|
|
|
|
my $file = $trynt_ws->get(); |
30
|
|
|
|
|
|
|
$file->save_to("./cnn.pdf"); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
or shortly |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $trynt_ws = WebService::Trynt::PDF->new( url => "http://www.cnn.com"); |
35
|
|
|
|
|
|
|
$trynt_ws->get("./cnn.pdf"); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 FUNCTIONS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 new |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
|
|
|
|
|
|
my ( $class, $xml ) = @_; |
47
|
|
|
|
|
|
|
my $self = bless { |
48
|
|
|
|
|
|
|
_xml => $xml, |
49
|
|
|
|
|
|
|
_tmp_file => File::Temp->new( UNLINK => 0 ), |
50
|
|
|
|
|
|
|
}, $class; |
51
|
|
|
|
|
|
|
$self->_parse_xml(); |
52
|
|
|
|
|
|
|
$self->_get_file(); |
53
|
|
|
|
|
|
|
$self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 save_to |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub save_to { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
my $filename = shift; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
move( $self->{_tmp_file}->filename, $filename ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _get_file { |
68
|
|
|
|
|
|
|
my ($self) = @_; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
71
|
|
|
|
|
|
|
$ua->agent("WebService::Trynt::PDF/$VERSION"); |
72
|
|
|
|
|
|
|
$ua->get( $self->{url}, ':content_file' => $self->{_tmp_file}->filename ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _parse_xml { |
76
|
|
|
|
|
|
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
my $xml = XMLin( $self->{_xml} ); |
78
|
|
|
|
|
|
|
$self->{md5} = $xml->{PDF}->{MD5}; |
79
|
|
|
|
|
|
|
$self->{url} = $xml->{PDF}->{PDF}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHOR |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Manu, C<< <> >> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 BUGS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
89
|
|
|
|
|
|
|
C, or through the web interface at |
90
|
|
|
|
|
|
|
L. |
91
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
92
|
|
|
|
|
|
|
your bug as I make changes. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SUPPORT |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
perldoc WebService::Trynt::PDF |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
You can also look for information at: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over 4 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * CPAN Ratings |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * Search CPAN |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Copyright 2006 Manu, all rights reserved. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
129
|
|
|
|
|
|
|
under the same terms as Perl itself. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; # End of WebService::Trynt::PDF::File |