| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Mail::Summary::Tools::ArchiveLink::GoogleGroups; | ||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | with "Mail::Summary::Tools::ArchiveLink::Base"; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use WWW::Mechanize; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use URI::QueryParam; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | sub message_uri { | ||||||||||||||||||||||||||
|
Subroutine
message_uri: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | my $uri = URI->new("http://groups.google.com/groups"); | |||||||||||||||||||||||||||
| 16 | 3 | $uri->query_param( selm => $self->message_id ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | $uri; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub thread_uri { } # FIXME Moose role composition | ||||||||||||||||||||||||||||
| 22 | has thread_uri => ( | ||||||||||||||||||||||||||||
| 23 | isa => "URI", | ||||||||||||||||||||||||||||
| 24 | is => "ro", | ||||||||||||||||||||||||||||
| 25 | lazy => 1, | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | default => sub { $_[0]->_thread_uri } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 27 | 2 | ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | has use_frames => ( | |||||||||||||||||||||||||||
| 30 | isa => "Bool", | ||||||||||||||||||||||||||||
| 31 | is => "rw", | ||||||||||||||||||||||||||||
| 32 | default => 1, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | has cache => ( | |||||||||||||||||||||||||||
| 36 | isa => "Object", | ||||||||||||||||||||||||||||
| 37 | is => "rw", | ||||||||||||||||||||||||||||
| 38 | required => 0, | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub cache_key { | ||||||||||||||||||||||||||
|
Subroutine
cache_key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | join(":", | |||||||||||||||||||||||||||
| 45 | qw/archive_links google_groups/, | ||||||||||||||||||||||||||||
| 46 | $self->message_id, | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub _munge_thread_uri { | ||||||||||||||||||||||||||
|
Subroutine
_munge_thread_uri: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 51 | 0 | my ( $self, $uri ) = @_; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | $uri =~ s/browse_thread/browse_frm/ if $self->use_frames; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | return $uri; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub _thread_uri { | ||||||||||||||||||||||||||
|
Subroutine
_thread_uri: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $uri = $self->_find_thread_uri || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->_find_thread_uri || (return)
MC/DC0%0/1
$self->_find_thread_uri || (return)
$self->_find_thread_uri
Truth table0%0/2
A
A= $self->_find_thread_uri
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | URI->new( $self->_munge_thread_uri($uri) ); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _find_thread_uri { | ||||||||||||||||||||||||||
|
Subroutine
_find_thread_uri: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 65 | 0 | my ( $self, $message_id ) = @_; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $cache = $self->cache; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $cache_key = $self->cache_key; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( my $uri = $cache && $cache->get($cache_key) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cache && $cache->get($cache_key)
MC/DC0%0/2
$cache && $cache->get($cache_key)
$cache
$cache->get($cache_key)
Truth table0%0/3
A && B
A= $cacheB= $cache->get($cache_key)
| |||||||||||||||||||||||||||||
| 72 | 0 | return $uri; | |||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||
| 74 | 0 | my $m = WWW::Mechanize->new; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my $uri = $self->message_uri; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | $m->get( $uri, 'user-agent' => "Mozilla" ); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ( my $link = $m->find_link( url_regex => qr#browse_(?:thread|frm)/thread/# ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | my $uri = $link->url_abs->as_string; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | $cache && $cache->set( $cache_key, $uri ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | return $uri | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | warn "no thread_uri for " . $self->message_id . ", falling back to gmane"; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | require Mail::Summary::Tools::ArchiveLink::Easy; | |||||||||||||||||||||||||||
| 90 | 0 | return Mail::Summary::Tools::ArchiveLink::Easy->gmane( $self->message_id )->thread_uri; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | __PACKAGE__; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||