| 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 | 2 | 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 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 2 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 2 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | |||||||||||
| 38 | 2 | ▶ | use constant URL => "http://www.trynt.com/pdf-api/v1/"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | |||||||||||
| 40 | 2 | ▶ | use WebService::Trynt::PDF::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | |||||||||||
| 42 | =head1 FUNCTIONS | ||||||||||
| 43 | |||||||||||
| 44 | =head2 new | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 49 | 0 | my ($class, %p) = @_; | |||||||||
| 50 | 0 | my $ua = LWP::UserAgent->new(); | |||||||||
| 51 | 0 | $ua->agent("WebService::Trynt::PDF/$VERSION"); | |||||||||
| 52 | 0 | bless { %p, ua => $ua }, $class; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub _var { | ||||||||
|
Subroutine
_var: not called CC=2 SCAR=17.9
| |||||||||||
| 56 | 0 | my $self = shift; | |||||||||
| 57 | 0 | my $key = shift; | |||||||||
| 58 | 0 | ▶ | $self->{$key} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | $self->{$key}; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | sub _request { | ||||||||
|
Subroutine
_request: not called CC=1 SCAR=6.9
| |||||||||||
| 63 | 0 | my ($self, %param) = @_; | |||||||||
| 64 | 0 | my $uri = URI->new(URL); | |||||||||
| 65 | 0 | $uri->query_form(%param); | |||||||||
| 66 | |||||||||||
| 67 | 0 | my $request = HTTP::Request->new(GET => $uri); | |||||||||
| 68 | 0 | return $self->{ua}->request($request); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | =head2 get | ||||||||||
| 72 | |||||||||||
| 73 | =cut | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 76 | 0 | my $self = shift; | |||||||||
| 77 | 0 | ▶ | if (exists $self->{url}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | my $res = $self->_request(u => $self->{url}, f => $self->{cache_flush}); | |||||||||
| 79 | 0 | ▶ | $self->{output} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 0 | my $file = WebService::Trynt::PDF::File->new($res->content); | |||||||||
| 81 | 0 | $file->save_to($self->{output}); | |||||||||
| 82 | 0 | return $file; | |||||||||
| 83 | } else { | ||||||||||
| 84 | 0 | require Carp; | |||||||||
| 85 | 0 | Carp::croak "You must specify an url to convert to PDF"; | |||||||||
| 86 | } | ||||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | =head2 url | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | 0 | ▶ | sub url { shift->_var('url', @_) }; | ||||||||
|
Subroutine
url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 94 | |||||||||||
| 95 | =head2 cache_flush | ||||||||||
| 96 | |||||||||||
| 97 | =cut | ||||||||||
| 98 | |||||||||||
| 99 | 0 | ▶ | sub cache_flush { shift->_var('cache_flush', @_) }; | ||||||||
|
Subroutine
cache_flush: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 100 | |||||||||||
| 101 | =head2 output | ||||||||||
| 102 | |||||||||||
| 103 | =cut | ||||||||||
| 104 | |||||||||||
| 105 | 0 | ▶ | sub output { shift->_var('output', @_) }; | ||||||||
|
Subroutine
output: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 106 | |||||||||||
| 107 | =head1 AUTHOR | ||||||||||
| 108 | |||||||||||
| 109 | Emmanuel Di Pretoro, C<< <<manu at bjornoya.net>> >> | ||||||||||
| 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<bug-webservice-trynt-pdf at rt.cpan.org>, or through the web interface at | ||||||||||
| 119 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-Trynt-PDF>. | ||||||||||
| 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<http://annocpan.org/dist/WebService-Trynt-PDF> | ||||||||||
| 136 | |||||||||||
| 137 | =item * CPAN Ratings | ||||||||||
| 138 | |||||||||||
| 139 | L<http://cpanratings.perl.org/d/WebService-Trynt-PDF> | ||||||||||
| 140 | |||||||||||
| 141 | =item * RT: CPAN's request tracker | ||||||||||
| 142 | |||||||||||
| 143 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WebService-Trynt-PDF> | ||||||||||
| 144 | |||||||||||
| 145 | =item * Search CPAN | ||||||||||
| 146 | |||||||||||
| 147 | L<http://search.cpan.org/dist/WebService-Trynt-PDF> | ||||||||||
| 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 | 2 | 1; # End of WebService::Trynt::PDF | |||||||||