File Coverage

blib/lib/WWW/Google/Groups/Thread.pm
Criterion Covered Total %
statement 15 62 24.1
branch 0 14 0.0
condition 0 3 0.0
subroutine 5 8 62.5
pod 0 3 0.0
total 20 90 22.2


line stmt bran cond sub pod time code
1             # $Id: Thread.pm,v 1.13 2003/09/22 03:14:55 cvspub Exp $
2             package WWW::Google::Groups::Thread;
3 1     1   4 use strict;
  1         1  
  1         27  
4              
5              
6 1     1   476 use WWW::Google::Groups::Article;
  1         3  
  1         32  
7 1     1   756 use WWW::Google::Groups::Vars;
  1         3  
  1         147  
8              
9 1     1   1074 use Storable qw(dclone);
  1         3686  
  1         194  
10              
11             sub new {
12 0     0 0   my ($pkg, $arg, $thread) = @_;
13 0           my $hash = dclone $arg;
14 0 0         return unless defined $thread;
15 0           delete $hash->{_threads};
16 0           $hash->{_cur_thread} = $thread;
17 0           $hash->{_cur_thread}->{_url} = $hash->{_server}.$thread->{_url};
18 0           bless $hash, $pkg;
19             }
20              
21 0     0 0   sub title() { $_[0]->{_cur_thread}->{_title} }
22              
23 1     1   1518 use WWW::Mechanize;
  1         182642  
  1         649  
24             sub next_article {
25 0     0 0   my $self = shift;
26 0           my $type = shift;
27              
28 0 0         if($self->{_goto_next_thread}){
29 0           $self->{_goto_next_thread} = 0;
30 0           return;
31             }
32              
33 0           my $content;
34 0 0 0       if( !ref ($self->{_mids}) or !scalar @{$self->{_mids}}){
  0            
35 0           $self->{_agent}->agent_alias( $agent_alias[int rand(scalar @agent_alias)] );
36 0           $self->{_agent}->get($self->{_cur_thread}->{_url});
37              
38 0           my @mids;
39              
40 0 0         if($self->{_cur_thread}->{_url} !~ /selm=/o){
41             # get the left frame first
42 0           ($content = $self->{_agent}->content) =~ /left src="(.+?)#s"/s;
43 0           $self->{_agent}->get($self->{_server}.$1);
44            
45 0           my @links;
46 0           foreach my $link (
  0            
47 0           map{s/\x23link\d+$//o;$_}
  0            
48 0           grep {/\x23link\d+$/}
49             map{$_->url}
50             $self->{_agent}->links
51             ){
52 0 0         push @links, $link unless $links[$#links-1] eq $link;
53             }
54              
55 0           foreach my $link (@links){
56 0           $self->{_agent}->get($self->{_server}.$link);
57 0           foreach my $mlink (grep{!m,^http://,io}
  0            
  0            
58 0           grep{!/rnum=/o}
59 0           grep{/selm=/o}
60             map{$_->url}$self->{_agent}->links){
61             # print $mlink,$/;
62 0           $mlink =~ /selm=(.+?)$/o;
63 0           push @mids, $1;
64             }
65             }
66             }
67             else {
68 0           $self->{_cur_thread}->{_url} =~ /selm=(.+?)$/o;
69 0           push @mids, $1;
70             }
71              
72             # use Data::Dumper;
73             # print Dumper \@mids;
74 0           $self->{_mids} = \@mids;
75             }
76              
77 0 0         $self->{_goto_next_thread} = 1 if 1==scalar@{$self->{_mids}};
  0            
78 0           my $this_mid = shift @{$self->{_mids}};
  0            
79 0           $self->{_agent}->get($self->{_server}."/groups?selm=${this_mid}&output=gplain");
80              
81 0 0         $type=~/raw/io?
82             $self->{_agent}->content() :
83             new WWW::Google::Groups::Article(\$self->{_agent}->content());
84             }
85              
86              
87              
88              
89              
90              
91             1;
92             __END__