| 1 | package WWW::Shorten::UserAgent; | ||||||||||
| 2 | |||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 7 | ▶ | use base 'LWP::UserAgent'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 7 | our $VERSION = '3.093'; | |||||||||
| 9 | 7 | $VERSION = eval $VERSION; | |||||||||
| 10 | |||||||||||
| 11 | sub get { | ||||||||||
| 12 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 13 | 0 | my $resp = $self->SUPER::get(@_); | |||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | die $resp->status_line if $resp->is_error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | 0 | return $resp; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | sub post { | ||||||||||
| 21 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
post: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 22 | 0 | my $resp = $self->SUPER::post(@_); | |||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | die $resp->status_line if $resp->is_error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | |||||||||||
| 26 | 0 | return $resp; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 7 | 1; | |||||||||
| 30 | |||||||||||
| 31 | =head1 NAME | ||||||||||
| 32 | |||||||||||
| 33 | WWW::Shorten::UserAgent - LWP::UserAgent subclass for WWW::Shorten modules. | ||||||||||
| 34 | |||||||||||
| 35 | =head1 SYNOPSIS | ||||||||||
| 36 | |||||||||||
| 37 | use strict; | ||||||||||
| 38 | use warnings; | ||||||||||
| 39 | use WWW::Shorten::UserAgent; | ||||||||||
| 40 | use Try::Tiny qw(try catch); | ||||||||||
| 41 | |||||||||||
| 42 | my $ua = WWW::Shorten::UserAgent->new; | ||||||||||
| 43 | |||||||||||
| 44 | my $resp = try { | ||||||||||
| 45 | $ua->get($url); | ||||||||||
| 46 | } | ||||||||||
| 47 | catch { | ||||||||||
| 48 | warn "Uh oh: $_"; | ||||||||||
| 49 | return undef; | ||||||||||
| 50 | }; | ||||||||||
| 51 | |||||||||||
| 52 | =head1 DESCRIPTION | ||||||||||
| 53 | |||||||||||
| 54 | Subclass of LWP::UserAgent which works the same way as the superclass | ||||||||||
| 55 | except that it throws an exception if the C<get> or C<post> method returns | ||||||||||
| 56 | an error. | ||||||||||
| 57 | |||||||||||
| 58 | See L<LWP::UserAgent> for the full documentation. | ||||||||||
| 59 | |||||||||||
| 60 | =head1 METHODS | ||||||||||
| 61 | |||||||||||
| 62 | =head2 get | ||||||||||
| 63 | |||||||||||
| 64 | Makes an HTTP GET request and throws an exception on error. | ||||||||||
| 65 | |||||||||||
| 66 | =head2 post | ||||||||||
| 67 | |||||||||||
| 68 | Makes an HTTP POST request and throws an exception on error. | ||||||||||
| 69 | |||||||||||
| 70 | =head1 AUTHOR | ||||||||||
| 71 | |||||||||||
| 72 | Dave Cross <dave@mag-sol.com> | ||||||||||
| 73 | |||||||||||
| 74 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 75 | |||||||||||
| 76 | Copyright (c) Magnum Solutions Ltd., 2012. All rights reserved. | ||||||||||
| 77 | |||||||||||
| 78 | This module is free software. You can redistribute it and/or | ||||||||||
| 79 | modify it under the terms of the Artistic License 2.0. | ||||||||||
| 80 | |||||||||||
| 81 | This program is distributed in the hope that it will be useful, | ||||||||||
| 82 | but without any warranty; without even the implied warranty of | ||||||||||
| 83 | merchantability or fitness for a particular purpose. | ||||||||||
| 84 | |||||||||||
| 85 | =head1 SEE ALSO | ||||||||||
| 86 | |||||||||||
| 87 | L<WWW::Shorten> | ||||||||||
| 88 | |||||||||||
| 89 | =cut | ||||||||||