File Coverage

blib/lib/WWW/Shorten/Simple.pm
Criterion Covered Total %
statement 12 37 32.4
branch 0 4 0.0
condition n/a
subroutine 4 12 33.3
pod 3 8 37.5
total 19 61 31.1


line stmt bran cond sub pod time code
1             package WWW::Shorten::Simple;
2              
3 2     2   1026 use strict;
  2         15  
  2         88  
4 2     2   58 use 5.008_001;
  2         9  
  2         106  
5             our $VERSION = '0.01';
6              
7 2     2   10 use Carp;
  2         3  
  2         974  
8              
9             sub new {
10 0     0 1   my($class, $impl, @args) = @_;
11              
12 0 0         unless ($impl) {
13 0           Carp::croak "WWW::Shorten subclass name is required";
14             }
15              
16 0           my $subclass = "WWW::Shorten::$impl";
17 0           $subclass =~ s!::!/!g;
18 0           $subclass .= ".pm";
19 0           eval { require $subclass };
  0            
20 0 0         Carp::croak "Can't load $impl: $@" if $@;
21              
22 0           bless { impl => "WWW::Shorten::$impl", args => \@args }, $class;
23             }
24              
25             sub shorten {
26 0     0 1   my $self = shift;
27 0           my($url) = @_;
28              
29 0           $self->call_method("makeashorterlink", $url, @{$self->{args}});
  0            
30             }
31              
32 0     0 0   sub makeashorterlink { shift->shorten(@_) }
33 0     0 0   sub short_link { shift->shorten(@_) }
34              
35             sub unshorten {
36 0     0 1   my $self = shift;
37 0           my($url) = @_;
38              
39 0           $self->call_method("makealongerlink", $url, @{$self->{args}});
  0            
40             }
41              
42 0     0 0   sub makealongerlink { shift->unshorten(@_) }
43 0     0 0   sub long_link { shift->unshorten(@_) }
44              
45             sub call_method {
46 0     0 0   my($self, $method, @args) = @_;
47              
48 2     2   12 no strict 'refs';
  2         11  
  2         142  
49 0           &{$self->{impl}."::$method"}(@args);
  0            
50             }
51              
52             1;
53             __END__