| 1 | package WWW::Topica::Index; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | =pod | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | WWW::Topica::Index - parse a single Topic mailing list index | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | my $index = WWW::Topic::Index->new($index_html); | ||
| 14 | |||
| 15 | foreach my $mess_id ($index->message_ids) { | ||
| 16 | # the mail has some information and also provides a link to the reply ... | ||
| 17 | my $mail = WWW::Topica::Mail->new($topica->fetch_mail($mess_id), $mess_id); | ||
| 18 | # which has other information (like the un-htmled mail and the email address) ... | ||
| 19 | my $reply = WWW::Topica::Reply->new($topica->fetch_reply($mail->id, $mail->eto), $mail->id, $mail->eto); | ||
| 20 | } | ||
| 21 | |||
| 22 | print "Next offset is ".$index->next."\n"; | ||
| 23 | print "Previous offset is ".$index->prev."\n"; | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | Used to parse a single index page from Topica.com's mailing list indexes. | ||
| 28 | |||
| 29 | =head1 METHODS | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | |||
| 34 | =head2 new <page html> | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | |||
| 39 | 3 | ▶ | sub new { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||
| 40 | 3 | my ($class, $html) = @_; | |
| 41 | |||
| 42 | 3 | my $self = { }; | |
| 43 | |||
| 44 | 3 | bless $self, $class; | |
| 45 | |||
| 46 | 3 | $self->parse($html); | |
| 47 | |||
| 48 | 3 | return $self; | |
| 49 | } | ||
| 50 | |||
| 51 | |||
| 52 | =head2 parse <html> | ||
| 53 | |||
| 54 | Parse the html to get message ids and next & prev offsets. | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | 3 | ▶ | sub parse { |
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
documented
| |||
| 59 | 3 | my ($self, $html) = @_; | |
| 60 | |||
| 61 | |||
| 62 | 3 | my $list = $self->{list}; | |
| 63 | 3 | ($self->{prev}) = ( $html =~ m!<A HREF="/lists/[^/]+/read\?sort\=d\&start\=(\d+)"><IMG SRC="http://lists.topica.com/art/rewind\.gif"!m ); | |
| 64 | |||
| 65 | 3 | ($self->{next}) = ( $html =~ m!<A HREF="/lists/[^/]+/read\?sort\=d\&start\=(\d+)"><IMG SRC="http://lists.topica.com/art/fastForward\.gif"!m ); | |
| 66 | |||
| 67 | 3 | my (@message_ids) = ($html =~ m!/lists/[^/]+/read/message\.html\?mid\=(\d+)!gs); | |
| 68 | |||
| 69 | |||
| 70 | 3 | $self->{_message_ids} = \@message_ids; | |
| 71 | |||
| 72 | } | ||
| 73 | |||
| 74 | |||
| 75 | =head2 message_ids | ||
| 76 | |||
| 77 | Return all the messge ids found on the page | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | 3 | ▶ | sub message_ids { |
|
Subroutine
message_ids: called CC=1 SCAR=0.0
Pod
documented
| |||
| 82 | 3 | my $self = shift; | |
| 83 | 3 | return @{$self->{_message_ids}}; | |
| 84 | } | ||
| 85 | |||
| 86 | =head2 prev | ||
| 87 | |||
| 88 | Return the offset of the previous page or undef if there is none. | ||
| 89 | |||
| 90 | =cut | ||
| 91 | |||
| 92 | 3 | ▶ | sub prev { |
|
Subroutine
prev: called CC=1 SCAR=0.0
Pod
documented
| |||
| 93 | 3 | return $_[0]->{prev}; | |
| 94 | } | ||
| 95 | |||
| 96 | |||
| 97 | =head2 next | ||
| 98 | |||
| 99 | Return the offset of the next page or undef if there is none. | ||
| 100 | |||
| 101 | =cut | ||
| 102 | |||
| 103 | 3 | ▶ | sub next { |
|
Subroutine
next: called CC=1 SCAR=0.0
Pod
documented
| |||
| 104 | 3 | return $_[0]->{next}; | |
| 105 | } | ||
| 106 | 1 | 1; | |
| 107 | |||
| 108 | =head1 AUTHOR | ||
| 109 | |||
| 110 | Simon Wistow <simon@thegestalt.org> | ||
| 111 | |||
| 112 | =head1 COPYRIGHT | ||
| 113 | |||
| 114 | Copyright (c) 2004, Simon Wistow | ||
| 115 | |||
| 116 | =cut | ||
| 117 | |||
| 118 | |||
| 119 | |||