File: generic.pm

package info (click to toggle)
libwww-shorten-perl 3.03-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 312 kB
  • sloc: perl: 253; makefile: 7
file content (85 lines) | stat: -rw-r--r-- 1,435 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# $Id$

=head1 NAME

WWW::Shorten::generic - Methods shared across all WWW::Shorten modules

=head1 SYNOPSIS

  use WWW::Shorten 'SomeSubclass';

=head1 DESCRIPTION

Contains methds that are shared across all WWW::Shorten implemenation
modules.

=cut

package WWW::Shorten::generic;

use 5.006;
use strict;
use warnings;

our $VERSION = 1.92;

use WWW::Shorten::UserAgent;
use Carp;

my %name_sets =
(
    default	=> [qw( makeashorterlink makealongerlink )],
    short	=> [qw( short_link long_link )],
);

sub import
{
    my $class = shift;
    my ($package) = caller;
    ($package) = caller(1) if $package eq 'WWW::Shorten';
    my $set = shift;
    if (defined $set and $set =~ /^ : (\w+) $/x) {
	$set = $1;
    } else {
	$set = 'default';
    }
    if ( exists $name_sets{$set} )
    {
	no strict 'refs';
	*{"${package}::$name_sets{$set}[0]"} =
	    *{ "${class}::$name_sets{default}[0]"};
	*{"${package}::$name_sets{$set}[1]"} =
	    *{ "${class}::$name_sets{default}[1]"};
    }
    else
    {
	croak "Unknown function set - $set.";
    }
}

my $ua;

=head1 FUNCTIONS

=head2 ua

Returns the object's LWP::Useragent attribute. Creates a new one if one
doesn't already exist.

=cut

sub ua
{
    my $self = shift;
    return $ua if defined $ua;
    my $v = $self->VERSION();
    $ua = WWW::Shorten::UserAgent->new(
	env_proxy => 1,
	timeout => 30,
	agent => "$self/$v",
	requests_redirectable => [],
    );
    return $ua;
}

1;