line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#$Id: AccountAutoDiscovery.pm,v 1.9 2005/09/02 02:59:30 naoya Exp $ |
2
|
|
|
|
|
|
|
package HTML::AccountAutoDiscovery; |
3
|
1
|
|
|
1
|
|
25332
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
5
|
use base qw ( Class::ErrorHandler ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
977
|
|
5
|
1
|
|
|
1
|
|
1403
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
62676
|
|
|
1
|
|
|
|
|
42
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
11
|
use vars qw ( $VERSION ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
592
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
9
|
|
|
|
|
|
|
my $MAX_SIZE = 1000000; # 1mb |
10
|
|
|
|
|
|
|
my $TIME_OUT = 10; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub find { |
13
|
1
|
|
|
1
|
0
|
16
|
my ($class, $uri) = @_; |
14
|
1
|
|
|
|
|
13
|
my $ua = LWP::UserAgent->new; |
15
|
1
|
|
|
|
|
4413
|
$ua->agent(join '/', $class, $class->VERSION); |
16
|
1
|
|
|
|
|
90
|
$ua->timeout($TIME_OUT); |
17
|
1
|
|
|
|
|
24
|
$ua->max_size($MAX_SIZE); |
18
|
1
|
|
|
|
|
13
|
$ua->parse_head(0); |
19
|
1
|
|
|
|
|
84
|
my $req = HTTP::Request->new(GET => $uri); |
20
|
1
|
|
|
|
|
10907
|
my @result; |
21
|
1
|
|
|
|
|
11
|
my $res = $ua->request($req); |
22
|
1
|
50
|
|
|
|
654767
|
return $class->error($res->status_line) unless $res->is_success; |
23
|
1
|
|
|
|
|
19
|
$class->find_in_html(\$res->content); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub find_in_html { |
27
|
2
|
|
|
2
|
0
|
526510
|
my ($class, $html) = @_; |
28
|
2
|
|
|
|
|
4
|
my @result; |
29
|
|
|
|
|
|
|
$class->each_account( |
30
|
|
|
|
|
|
|
sub { |
31
|
2
|
|
|
2
|
|
4
|
my( $srvname, $account ) = @_; |
32
|
2
|
|
|
|
|
22
|
push @result, { service => $srvname, account => $account }; |
33
|
2
|
|
|
|
|
16
|
}, $html |
34
|
|
|
|
|
|
|
); |
35
|
2
|
|
|
|
|
40
|
@result; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub each_account { |
39
|
2
|
|
|
2
|
0
|
6
|
my( $self, $yield, $sp ) = @_; |
40
|
2
|
50
|
|
|
|
9
|
ref( $yield ) eq 'CODE' |
41
|
|
|
|
|
|
|
or die __PACKAGE__ . "\:\:each_account needs CODE_REF\n"; |
42
|
2
|
|
|
|
|
4
|
my $foafuri = "http://xmlns\\.com/foaf/0\\.1/"; |
43
|
2
|
|
|
|
|
23
|
while ( $$sp =~ m{()}sg) { |
44
|
2
|
|
|
|
|
15
|
my $rdf = $1; |
45
|
2
|
|
|
|
|
4
|
my $foaf = ''; |
46
|
2
|
50
|
|
|
|
41
|
if ( $rdf =~ m{xmlns:(\w+)="$foafuri"}o ) { |
|
|
0
|
|
|
|
|
|
47
|
2
|
|
|
|
|
5
|
$foaf = $1 . ':'; |
48
|
|
|
|
|
|
|
} elsif ( $rdf =~ m{xmlns="$foafuri"}o ) { |
49
|
0
|
|
|
|
|
0
|
$foaf = ''; |
50
|
|
|
|
|
|
|
} else { |
51
|
0
|
|
|
|
|
0
|
next; |
52
|
|
|
|
|
|
|
} |
53
|
2
|
|
|
|
|
31
|
while ( $rdf =~ m{<(${foaf}holdsAccount)(.*?)\1>}sg ) { |
54
|
2
|
|
|
|
|
7
|
my $onlineaccount = $2; |
55
|
2
|
|
|
|
|
3
|
my( $servicehomepage, $accountname ); |
56
|
2
|
50
|
|
|
|
37
|
if ( $onlineaccount =~ m{ |
57
|
|
|
|
|
|
|
<${foaf}accountServiceHomepage[^>]+rdf:resource="(.*)" |
58
|
|
|
|
|
|
|
}xs ) { |
59
|
2
|
|
|
|
|
4
|
$servicehomepage = $1; |
60
|
|
|
|
|
|
|
} |
61
|
2
|
50
|
|
|
|
41
|
if ( $onlineaccount =~ m{ |
62
|
|
|
|
|
|
|
<${foaf}accountName>[\s\n]*([^<>]+)[\s\n]*${foaf}accountName> |
63
|
|
|
|
|
|
|
}xs ) { |
64
|
0
|
|
|
|
|
0
|
$accountname = $1; |
65
|
|
|
|
|
|
|
} |
66
|
2
|
50
|
|
|
|
21
|
if ( $onlineaccount =~ m{${foaf}accountName="([^<>]+?)"} ) { |
67
|
2
|
|
|
|
|
5
|
$accountname = $1; |
68
|
|
|
|
|
|
|
} |
69
|
2
|
50
|
33
|
|
|
20
|
if ( defined( $servicehomepage ) && defined( $accountname ) ) { |
70
|
2
|
|
|
|
|
5
|
$yield->( $servicehomepage, $accountname ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |