line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
1740
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
66
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Net::Delicious::Export::Post; |
4
|
1
|
|
|
1
|
|
5
|
use base qw (Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
97
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# $Id: Post.pm,v 1.6 2005/12/11 19:40:53 asc Exp $ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Net::Delicious::Export::Post - shared functions for exporting del.icio.us posts |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Net::Delicious; |
15
|
|
|
|
|
|
|
use Net::Delicious::Export::Post qw (group_by_tag); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $del = Net::Delicious->new({...}); |
18
|
|
|
|
|
|
|
my $it = $del->recent_posts(); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $hr_ordered = group_by_tag($it); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Shared function for exporting del.icio.us posts. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
8
|
use vars qw ($VERSION @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
896
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$VERSION = '1.1'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
@EXPORT_OK = qw (group_by_tag |
33
|
|
|
|
|
|
|
mk_bookmarkid); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# used by &_addbm |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $by_time = sub { |
38
|
|
|
|
|
|
|
$a->time() cmp $b->time(); |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 FUNCTIONS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 &group_by_tag(Net::Delicious::Iterator,\&sort_function) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Build a nested hash reference of posts grouped by tag. This |
49
|
|
|
|
|
|
|
function will DWIM with "hierarchical" tags. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Posts for any given tag set will be grouped as an array |
52
|
|
|
|
|
|
|
reference. They will be ordered by their timestamp. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Valid arguments are : |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=over 4 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item * |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
B I |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
An iterator object of I objects. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item * |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
B |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Used as an argument for passing to Perl's I function. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The default behaviour is to sort tags alphabetically. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=back |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Returns a hash reference. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub group_by_tag { |
79
|
0
|
|
|
0
|
|
|
my $posts = shift; |
80
|
0
|
|
|
|
|
|
my $sort = shift; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my %ordered = (); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
while (my $bm = $posts->next()) { |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Create a list of tags |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
0
|
|
|
|
my $tag = $bm->tag() || "unsorted"; |
89
|
0
|
|
|
|
|
|
$tag =~ s/\s{2,*}/ /g; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my @tags = sort $sort split(/[\s,]/,$tag); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Pull the first tag off the list |
94
|
|
|
|
|
|
|
# and use it as the actual bookmark |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
&_addtag(\%ordered, shift @tags, $bm); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Everything else is just an alias |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
map { |
101
|
0
|
|
|
|
|
|
&_addtag(\%ordered, $_, &mk_bookmarkid($bm)); |
102
|
|
|
|
|
|
|
} @tags; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
return \%ordered; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 &mk_bookmarkid(Net::Delicious::Post) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Returns a I object. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
The object subclasses I but since its |
113
|
|
|
|
|
|
|
I method is overloaded to return the value of its |
114
|
|
|
|
|
|
|
B method you can, pretty much, just treat it like |
115
|
|
|
|
|
|
|
a string. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub mk_bookmarkid { |
120
|
0
|
|
|
0
|
|
|
return Net::Delicious::Export::Post::Bookmarkid->new($_[0]); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _addtag { |
125
|
0
|
|
|
0
|
|
|
my $dict = shift; |
126
|
0
|
|
|
|
|
|
my $tag = shift; |
127
|
0
|
|
|
|
|
|
my $bm = shift; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# print STDERR "[add tag] '$tag' '$bm'\n"; |
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
my @tree = ($tag =~ m!/!) ? grep { /^\w/ } split("/",$tag) : ($tag); |
|
0
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $count = scalar(@tree); |
133
|
|
|
|
|
|
|
|
134
|
0
|
0
|
|
|
|
|
if ($count == 1) { |
135
|
0
|
|
0
|
|
|
|
$dict->{$tag} ||= []; |
136
|
0
|
|
|
|
|
|
&_addbm($dict->{$tag}, $bm); |
137
|
0
|
|
|
|
|
|
return; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
my $ref = $dict; |
141
|
0
|
|
|
|
|
|
my $current = 1; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
map { |
144
|
|
|
|
|
|
|
|
145
|
0
|
0
|
|
|
|
|
if ($current == $count) { |
|
0
|
|
|
|
|
|
|
146
|
0
|
|
0
|
|
|
|
$ref->{$_} ||= []; |
147
|
0
|
|
|
|
|
|
&_addbm($ref->{$_},$bm); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
else { |
151
|
0
|
|
0
|
|
|
|
$ref->{$_} ||= {}; |
152
|
0
|
|
|
|
|
|
$ref = $ref->{$_}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$current++; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
} @tree; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub _addbm { |
161
|
0
|
|
|
0
|
|
|
my $list = shift; |
162
|
0
|
|
|
|
|
|
my $bm = shift; |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
@$list = sort $by_time (@$list,$bm); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
package Net::Delicious::Export::Post::Bookmarkid; |
168
|
1
|
|
|
1
|
|
7
|
use base qw (Net::Delicious::Post); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
827
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
use MD5; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
use overload q("") => sub { shift->bookmarkid() }; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub new { |
175
|
|
|
|
|
|
|
my $pkg = shift; |
176
|
|
|
|
|
|
|
my $bm = shift; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
my %id = %$bm; |
179
|
|
|
|
|
|
|
$id{bookmarkid} = MD5->hexhash($bm->href()); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
return bless \%id, $pkg; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub bookmarkid { |
185
|
|
|
|
|
|
|
my $self = shift; |
186
|
|
|
|
|
|
|
return $self->{bookmarkid}; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 VERSION |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1.1 |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 DATE |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
$Date: 2005/12/11 19:40:53 $ |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 AUTHOR |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Aaron Straup Cope |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 SEE AlSO |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
L |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 LICENSE |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Copyright (c) 2004 Aaron Straup Cope. All Rights Reserved. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This is free software, you may use it and distribute it under the |
210
|
|
|
|
|
|
|
same terms as Perl itself. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=cut |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
return 1; |