line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bookmarks::XML; |
2
|
5
|
|
|
5
|
|
15
|
use base 'Bookmarks::Parser'; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
249
|
|
3
|
5
|
|
|
5
|
|
17
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
97
|
|
4
|
5
|
|
|
5
|
|
13
|
use warnings; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
74
|
|
5
|
5
|
|
|
5
|
|
2140
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
|
|
|
|
|
|
my ($class, %opts) = @_; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# %opts = check_options(%opts); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $self = bless({%opts}, ref($class) || $class); |
13
|
|
|
|
|
|
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub parse_file { |
17
|
|
|
|
|
|
|
my ($sel, $filename) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
return if (!$filename || !-e $filename); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $bookmarks = XMLin($filename, ForceArray => ['folder']); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get_header_as_string { |
26
|
|
|
|
|
|
|
my ($self) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $now = scalar localtime; |
29
|
|
|
|
|
|
|
my $title = $self->{_title} || 'Bookmarks'; |
30
|
|
|
|
|
|
|
my $header = << "XML"; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
XML |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return $header; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub get_item_as_string { |
44
|
|
|
|
|
|
|
my ($self, $item) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if (!defined $item->{id} || !$self->{_items}{ $item->{id} }) { |
47
|
|
|
|
|
|
|
warn "No such item in get_item_as_string"; |
48
|
|
|
|
|
|
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $string = ''; |
52
|
|
|
|
|
|
|
my ($id, $url, $name, $visited, $created, $modified, $icon, $desc, |
53
|
|
|
|
|
|
|
$expand, $trash, $order) = ( |
54
|
|
|
|
|
|
|
$item->{id} || 0, |
55
|
|
|
|
|
|
|
$item->{url} || '', |
56
|
|
|
|
|
|
|
$item->{name} || '', |
57
|
|
|
|
|
|
|
$item->{visited} || 0, |
58
|
|
|
|
|
|
|
$item->{created} || time(), |
59
|
|
|
|
|
|
|
$item->{modified} || 0, |
60
|
|
|
|
|
|
|
$item->{icon} || '', |
61
|
|
|
|
|
|
|
$item->{description} || '', |
62
|
|
|
|
|
|
|
$item->{expanded} || '', |
63
|
|
|
|
|
|
|
$item->{trash} || '', |
64
|
|
|
|
|
|
|
$item->{order} || '' |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
if ($item->{type} eq 'folder') { |
68
|
|
|
|
|
|
|
$string .= << "XML"; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
XML |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$string .= $self->get_item_as_string($self->{_items}{$_}) |
73
|
|
|
|
|
|
|
foreach (@{ $item->{children} }); |
74
|
|
|
|
|
|
|
$string .= " \n"; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
elsif ($item->{type} eq 'url') { |
77
|
|
|
|
|
|
|
$string .= << "XML"; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
XML |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return $string; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_footer_as_string { |
87
|
|
|
|
|
|
|
my ($self) = @_; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $footer = << "XML"; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
XML |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
return $footer; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Bookmarks::Parser::XML - Backend for XML format |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 DESCRIPTION |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This backend is completely untested, and probably does not work yet. use at own risk. |
105
|
|
|
|
|
|
|
It will probably be replaced with an XBEL based backend in a future release. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 METHODS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 get_footer_as_string |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 get_header_as_string |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 get_item_as_string |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 new |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 parse_file |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
For these methods, consult L documentation. |
120
|
|
|
|
|
|
|
They are overridden because of the XML behaviour here. |
121
|
|
|
|
|
|
|
Interface remains the same. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |