File Coverage

lib/WWW/Mixi/Scraper.pm
Criterion Covered Total %
statement 24 52 46.1
branch 0 12 0.0
condition 0 3 0.0
subroutine 8 11 72.7
pod 2 2 100.0
total 34 80 42.5


line stmt bran cond sub pod time code
1             package WWW::Mixi::Scraper;
2            
3 1     1   892 use strict;
  1         3  
  1         39  
4 1     1   5 use warnings;
  1         3  
  1         52  
5            
6             our $VERSION = '0.34';
7            
8 1     1   6 use String::CamelCase qw( decamelize );
  1         2  
  1         80  
9 1     1   706 use Module::Find;
  1         1258  
  1         81  
10            
11 1     1   15 use WWW::Mixi::Scraper::Mech;
  1         2  
  1         10  
12 1     1   30 use WWW::Mixi::Scraper::Utils qw( _uri );
  1         2  
  1         112  
13            
14             sub new {
15 0     0 1   my ($class, %options) = @_;
16            
17 0           my $mode = delete $options{mode};
18 0 0 0       $mode = ( $mode && uc $mode eq 'TEXT' ) ? 'TEXT' : 'HTML';
19            
20 0           my $mech = WWW::Mixi::Scraper::Mech->new(%options);
21            
22 0           my $self = bless { mech => $mech, mode => $mode }, $class;
23            
24 1     1   5 no strict 'refs';
  1         1  
  1         27  
25 1     1   6 no warnings 'redefine';
  1         2  
  1         391  
26 0           foreach my $plugin ( findsubmod 'WWW::Mixi::Scraper::Plugin' ) {
27 0           my ($name) = decamelize($plugin) =~ /(\w+)$/;
28 0           $self->{$name} = $plugin;
29 0           *{"$class\::$name"} = sub {
30 0     0     my $self = shift;
31 0           my $package = $self->{$name};
32 0 0         return $package if ref $package;
33 0 0         eval "require $package" or die $@;
34 0           $self->{$name} = $package->new( mech => $mech, mode => $mode );
35 0           };
36             }
37            
38 0           $self;
39             }
40            
41             sub parse {
42 0     0 1   my ($self, $uri, %options) = @_;
43            
44 0 0         $uri = _uri($uri) unless ref $uri eq 'URI';
45            
46 0           my $path = $uri->path;
47 0           $path =~ s|^/||;
48 0           $path =~ s|\.pl$||;
49            
50 0 0         unless ( $self->can($path) ) {
51 0           warn "You don't have a proper plugin to handle $path";
52 0           return;
53             }
54            
55 0           foreach my $key ( $uri->query_param ) {
56 0 0         next if exists $options{$key};
57 0           $options{$key} = $uri->query_param($key);
58             }
59 0           $self->$path->parse( %options );
60             }
61            
62             1;
63            
64             __END__