line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Social::Mapper::SiteMap; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
2843
|
use strict; |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
502
|
|
4
|
13
|
|
|
13
|
|
8227
|
use JSON::Any; |
|
13
|
|
|
|
|
234452
|
|
|
13
|
|
|
|
|
97
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Net::Social::Mapper::SiteMap - information about know services around the internet |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $sitemap = Net::Social::Mapper::SiteMap; |
13
|
|
|
|
|
|
|
my $info = $sitemap->profile($user, $service); |
14
|
|
|
|
|
|
|
my ($user, $service) = $sitemap->url_to_service($url); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This is designed to be overriden and replaced with a more scalable |
20
|
|
|
|
|
|
|
database if necessary. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Alternatively the information could come from Google's C |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
http://code.google.com/p/google-sgnodemapper/ |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 METHODS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 new |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Instantiate a new sitemap. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
sub new { |
34
|
30
|
|
|
30
|
1
|
973
|
my $class = shift; |
35
|
30
|
|
|
|
|
100
|
my %opts = @_; |
36
|
30
|
|
|
|
|
107
|
my $self = bless \%opts, $class; |
37
|
30
|
|
|
|
|
117
|
$self->_init; |
38
|
30
|
|
|
|
|
214
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
30
|
|
|
30
|
|
48
|
sub _init { } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _get_sitemap { |
45
|
36
|
|
|
36
|
|
71
|
my $self = shift; |
46
|
36
|
100
|
|
|
|
131
|
return $self->{_sitemap} if $self->{_sitemap}; |
47
|
30
|
|
|
|
|
100
|
my $fh = *DATA; |
48
|
30
|
|
|
|
|
83
|
my $off = tell($fh); |
49
|
30
|
|
|
|
|
212
|
my $json = JSON::Any->new; |
50
|
30
|
|
|
|
|
2844
|
my $data = do { local $/; <$fh> }; |
|
30
|
|
|
|
|
134
|
|
|
30
|
|
|
|
|
2515
|
|
51
|
30
|
|
|
|
|
199
|
seek($fh, $off, 0); |
52
|
30
|
|
33
|
|
|
256
|
return $self->{_sitemap} ||= $json->decode($data); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 profile [user] |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Returns a hash ref with all the known information about C. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
If C is passed in then any urls will be updated to include that information; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Returns undef if the service isn't known. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
sub profile { |
65
|
19
|
|
|
19
|
1
|
39
|
my $self = shift; |
66
|
19
|
|
50
|
|
|
68
|
my $service = shift || return; |
67
|
19
|
|
|
|
|
46
|
my $user = shift; |
68
|
19
|
|
|
|
|
72
|
my $site = $self->_get_sitemap; |
69
|
19
|
|
|
|
|
8799
|
my $val = $service; |
70
|
19
|
|
|
|
|
40
|
do { |
71
|
20
|
|
|
|
|
81
|
$val = $site->{$val}; |
72
|
20
|
100
|
66
|
|
|
5200
|
return unless defined $val && $val !~ m!^\s*$!; |
73
|
16
|
100
|
|
|
|
110
|
$service = $val unless ref($val) ne ""; |
74
|
|
|
|
|
|
|
} until (ref($val) ne ""); |
75
|
15
|
100
|
|
|
|
81
|
$val = $self->_visit($val, $user) if defined $user; |
76
|
15
|
|
|
|
|
43
|
$val->{service} = $service; |
77
|
15
|
|
|
|
|
101
|
return $val; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _visit { |
81
|
150
|
|
|
150
|
|
191
|
my $self = shift; |
82
|
150
|
|
|
|
|
170
|
my $struct = shift; |
83
|
150
|
|
|
|
|
208
|
my $user = shift; |
84
|
150
|
|
|
|
|
316
|
my $ref = ref($struct); |
85
|
|
|
|
|
|
|
|
86
|
150
|
100
|
66
|
|
|
733
|
if (!defined $ref || $ref eq "") { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
87
|
109
|
|
|
|
|
289
|
$struct =~ s!%user!$user!msg; |
88
|
|
|
|
|
|
|
} elsif ($ref eq 'SCALAR') { |
89
|
0
|
|
|
|
|
0
|
$$struct = $self->_visit($$struct, $user); |
90
|
|
|
|
|
|
|
} elsif ($ref eq 'HASH') { |
91
|
14
|
|
|
|
|
70
|
foreach my $key (keys %$struct) { |
92
|
90
|
|
|
|
|
238
|
$struct->{$key} = $self->_visit($struct->{$key}, $user); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} elsif ($ref eq 'ARRAY') { |
95
|
27
|
|
|
|
|
55
|
$struct = [ map { $self->_visit($_, $user) } @$struct ]; |
|
46
|
|
|
|
|
165
|
|
96
|
|
|
|
|
|
|
} |
97
|
150
|
|
|
|
|
475
|
return $struct; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 url_to_service |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Take a url and work out what username and service it is |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
sub url_to_service { |
106
|
17
|
|
|
17
|
1
|
49
|
my $self = shift; |
107
|
17
|
|
|
|
|
30
|
my $url = shift; |
108
|
17
|
100
|
|
|
|
135
|
$url = "http://$url" unless $url =~ m![a-z]+:\/\/!i; |
109
|
|
|
|
|
|
|
|
110
|
17
|
|
|
|
|
66
|
my $sitemap = $self->_get_sitemap; |
111
|
|
|
|
|
|
|
|
112
|
17
|
|
|
|
|
5740
|
foreach my $service (keys %$sitemap) { |
113
|
959
|
100
|
|
|
|
2375
|
next unless ref($sitemap->{$service}); |
114
|
716
|
|
50
|
|
|
1828
|
my $regex = $sitemap->{$service}->{regex} || next; |
115
|
716
|
50
|
|
|
|
1796
|
my @regexes = (ref($regex)) ? @$regex : ($regex); |
116
|
716
|
|
|
|
|
950
|
foreach my $test (@regexes) { |
117
|
1044
|
|
|
|
|
1692
|
$test =~ s!\?!\\?!g; |
118
|
1044
|
100
|
|
|
|
18448
|
next unless $url =~ m!$test!; |
119
|
10
|
50
|
|
|
|
40
|
next unless defined $1; |
120
|
10
|
|
|
|
|
74
|
return ($1, $service); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# The default |
125
|
7
|
|
|
|
|
88
|
return ($url, 'website'); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
### |
129
|
|
|
|
|
|
|
# Needed |
130
|
|
|
|
|
|
|
## |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Catser |
133
|
|
|
|
|
|
|
# ColourLovers |
134
|
|
|
|
|
|
|
# Corkd |
135
|
|
|
|
|
|
|
# Dogster |
136
|
|
|
|
|
|
|
# Gametap |
137
|
|
|
|
|
|
|
# Goodreads |
138
|
|
|
|
|
|
|
# Google |
139
|
|
|
|
|
|
|
# Hi5 |
140
|
|
|
|
|
|
|
# Iconbuffet |
141
|
|
|
|
|
|
|
# Icq |
142
|
|
|
|
|
|
|
# Iminta |
143
|
|
|
|
|
|
|
# IStockPhoto |
144
|
|
|
|
|
|
|
# IUseThis |
145
|
|
|
|
|
|
|
# IWatchThis |
146
|
|
|
|
|
|
|
# Mog |
147
|
|
|
|
|
|
|
# Multiply |
148
|
|
|
|
|
|
|
# Netflix |
149
|
|
|
|
|
|
|
# NetVibes |
150
|
|
|
|
|
|
|
# NewsVine |
151
|
|
|
|
|
|
|
# Ning |
152
|
|
|
|
|
|
|
# Ohloh |
153
|
|
|
|
|
|
|
# Opera |
154
|
|
|
|
|
|
|
# p0pulist |
155
|
|
|
|
|
|
|
# Skype |
156
|
|
|
|
|
|
|
# Sonicliving |
157
|
|
|
|
|
|
|
# Spin.de |
158
|
|
|
|
|
|
|
# Stumbleupon |
159
|
|
|
|
|
|
|
# Tabblo |
160
|
|
|
|
|
|
|
# Technorati |
161
|
|
|
|
|
|
|
# Threadless |
162
|
|
|
|
|
|
|
# Uncrate |
163
|
|
|
|
|
|
|
# Viddler |
164
|
|
|
|
|
|
|
# Virb |
165
|
|
|
|
|
|
|
# Wakoopa |
166
|
|
|
|
|
|
|
# Wists |
167
|
|
|
|
|
|
|
1; |
168
|
|
|
|
|
|
|
__DATA__ |