FollowLinks.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 57 CC 3 SCAR 16.7
CC
3
Cov
0%
follow_links
12.0
setup
2.0
BEGIN
2.0
CRAP 5.3
1 # $Id: /mirror/perl/GunghoX-FollowLinks/trunk/lib/GunghoX/FollowLinks.pm 40585 2008-01-29T15:58:05.363572Z daisuke $
2 #
3 # Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>
4 # All rights reserved.
5  
6 package GunghoX::FollowLinks;
7 use strict;
8 use warnings;
9 use base qw(Gungho::Component);
10 use Class::Null;
11 use Gungho::Util;
12 our $VERSION = '0.00006';
13  
14 __PACKAGE__->mk_classdata($_) for qw(follow_links_parsers follow_link_log);
15  
16 sub setup
17 {
18 my $c = shift;
19 $c->next::method();
20  
21 my $config = $c->config->{follow_links};
22  
23 $c->follow_links_parsers( {} );
24 foreach my $parser_config (@{ $config->{parsers} }) {
25 my $module = $parser_config->{module};
26 my $pkg = Gungho::Util::load_module($module, 'GunghoX::FollowLinks::Parser');
27 my $obj = $pkg->new( %{ $parser_config->{config} } );
28  
29 $obj->register( $c );
30 }
31  
32 $c;
33 }
34  
35 sub follow_links
36 {
37 my ($c, $response) = @_;
38  
39 eval {
40 my $content_type = $response->content_type;
41 my $parser =
42 $c->follow_links_parsers->{ $content_type } ||
43 $c->follow_links_parsers->{ 'DEFAULT' }
44 ;
45 if ($parser) {
46 $c->log->debug( "Parsing links for " . $response->request->uri );
47 $parser->parse( $c, $response );
48 }
49 };
50 warn if $@;
51 }
52  
53 1;
54  
55 __END__