line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Icon.pm 1933 2006-04-22 04:53:48Z btrott $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package WWW::Blog::Metadata::Icon; |
4
|
1
|
|
|
1
|
|
2135
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
70
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1351
|
use WWW::Blog::Metadata; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use XML::FOAF; |
10
|
|
|
|
|
|
|
use URI; |
11
|
|
|
|
|
|
|
use LWP::UserAgent; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
WWW::Blog::Metadata->mk_accessors(qw( icon_uri favicon_uri foaf_icon_uri )); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub on_got_html { |
16
|
|
|
|
|
|
|
my $class = shift; |
17
|
|
|
|
|
|
|
my($meta, $html, $base_uri) = @_; |
18
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
19
|
|
|
|
|
|
|
my $req = HTTP::Request->new(HEAD => $base_uri . 'favicon.ico'); |
20
|
|
|
|
|
|
|
my $res = $ua->request($req); |
21
|
|
|
|
|
|
|
if ($res->is_success) { |
22
|
|
|
|
|
|
|
$meta->favicon_uri($base_uri . 'favicon.ico'); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
my $foaf_uri = XML::FOAF->find_foaf_in_html($html, $base_uri) |
25
|
|
|
|
|
|
|
or return; |
26
|
|
|
|
|
|
|
my $foaf = XML::FOAF->new(URI->new($foaf_uri)) |
27
|
|
|
|
|
|
|
or return; |
28
|
|
|
|
|
|
|
$meta->foaf_icon_uri($foaf->person->img || $foaf->person->depiction); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
sub on_got_html_order { 99 } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub on_got_tag { |
33
|
|
|
|
|
|
|
my $class = shift; |
34
|
|
|
|
|
|
|
my($meta, $tag, $attr, $base_uri) = @_; |
35
|
|
|
|
|
|
|
if ($tag eq 'link' && $attr->{rel}) { |
36
|
|
|
|
|
|
|
my %rel = map { $_ => 1 } split /\s+/, lc $attr->{rel}; |
37
|
|
|
|
|
|
|
if ($rel{icon}) { |
38
|
|
|
|
|
|
|
$meta->favicon_uri(URI->new_abs($attr->{href}, $base_uri))->as_string; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
sub on_got_tag_order { 99 } |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub on_finished { |
45
|
|
|
|
|
|
|
my $class = shift; |
46
|
|
|
|
|
|
|
my($meta) = @_; |
47
|
|
|
|
|
|
|
$meta->icon_uri($meta->foaf_icon_uri || $meta->favicon_uri); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
sub on_finished_order { 99 } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
__END__ |