| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::Trynt::PDF; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =head1 NAME | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | WebService::Trynt::PDF - Easy Interface for Trynt PDF Web Services | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 VERSION | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | Version 0.01 | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =cut | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $VERSION = '0.01'; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | WebService::Trynt::PDF is an interface for Trynt Web Services, so you can convert an URL into a PDF file. | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | use WebService::Trynt::PDF; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | my $trynt_ws = WebService::Trynt::PDF->new( url => "http://www.cnn.com", cache_flush => 0); | 
| 22 |  |  |  |  |  |  | my $file = $trynt_ws->get(); | 
| 23 |  |  |  |  |  |  | $file->save_to("./cnn.pdf"); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | or shortly | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | my $trynt_ws = WebService::Trynt::PDF->new( url => "http://www.cnn.com"); | 
| 28 |  |  |  |  |  |  | $trynt_ws->get("./cnn.pdf"); | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =cut | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 1 |  |  | 1 |  | 26985 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 37 |  | 
| 33 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 37 |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 1 |  |  | 1 |  | 4254 | use LWP::UserAgent; | 
|  | 1 |  |  |  |  | 85454 |  | 
|  | 1 |  |  |  |  | 41 |  | 
| 36 | 1 |  |  | 1 |  | 11 | use URI; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 1 |  |  | 1 |  | 7 | use constant URL => "http://www.trynt.com/pdf-api/v1/"; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 83 |  | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 1 |  |  | 1 |  | 802 | use WebService::Trynt::PDF::File; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head1 FUNCTIONS | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =head2 new | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =cut | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | sub new { | 
| 49 |  |  |  |  |  |  | my ($class, %p) = @_; | 
| 50 |  |  |  |  |  |  | my $ua = LWP::UserAgent->new(); | 
| 51 |  |  |  |  |  |  | $ua->agent("WebService::Trynt::PDF/$VERSION"); | 
| 52 |  |  |  |  |  |  | bless { %p, ua => $ua }, $class; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub _var { | 
| 56 |  |  |  |  |  |  | my $self = shift; | 
| 57 |  |  |  |  |  |  | my $key = shift; | 
| 58 |  |  |  |  |  |  | $self->{$key} = shift if @_; | 
| 59 |  |  |  |  |  |  | $self->{$key}; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub _request { | 
| 63 |  |  |  |  |  |  | my ($self, %param) = @_; | 
| 64 |  |  |  |  |  |  | my $uri = URI->new(URL); | 
| 65 |  |  |  |  |  |  | $uri->query_form(%param); | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | my $request = HTTP::Request->new(GET => $uri); | 
| 68 |  |  |  |  |  |  | return $self->{ua}->request($request); | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head2 get | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =cut | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub get { | 
| 76 |  |  |  |  |  |  | my $self = shift; | 
| 77 |  |  |  |  |  |  | if (exists $self->{url}) { | 
| 78 |  |  |  |  |  |  | my $res = $self->_request(u => $self->{url}, f => $self->{cache_flush}); | 
| 79 |  |  |  |  |  |  | $self->{output} = shift if @_; | 
| 80 |  |  |  |  |  |  | my $file = WebService::Trynt::PDF::File->new($res->content); | 
| 81 |  |  |  |  |  |  | $file->save_to($self->{output}); | 
| 82 |  |  |  |  |  |  | return $file; | 
| 83 |  |  |  |  |  |  | } else { | 
| 84 |  |  |  |  |  |  | require Carp; | 
| 85 |  |  |  |  |  |  | Carp::croak "You must specify an url to convert to PDF"; | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head2 url | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =cut | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | sub url { shift->_var('url', @_) }; | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head2 cache_flush | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =cut | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | sub cache_flush { shift->_var('cache_flush', @_) }; | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =head2 output | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =cut | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | sub output { shift->_var('output', @_) }; | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =head1 AUTHOR | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | Emmanuel Di Pretoro, C<< <> >> | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | http://trynt.com/trynt-api-pdf/ | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head1 BUGS | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 118 |  |  |  |  |  |  | C, or through the web interface at | 
| 119 |  |  |  |  |  |  | L. | 
| 120 |  |  |  |  |  |  | I will be notified, and then you'll automatically be notified of progress on | 
| 121 |  |  |  |  |  |  | your bug as I make changes. | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =head1 SUPPORT | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | perldoc WebService::Trynt::PDF | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | You can also look for information at: | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | =over 4 | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | L | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | L | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =item * RT: CPAN's request tracker | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | L | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =item * Search CPAN | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | L | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =back | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | Copyright 2006 Emmanuel Di Pretoro, all rights reserved. | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 158 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =cut | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | 1; # End of WebService::Trynt::PDF |