lib/Bookmarks/XML.pm

filter: Statementstmt 32.5% 13 / 40 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 44.4% 4 / 9 Podpod 100% 5 / 5 totaltotal 19.4% 22 / 113 CC 21 SCAR 52.0
CC
21
Cov
16%
get_item_as_string
306.0
parse_file
12.0
new
6.0
CRAP 181.7
« lib/Bookmarks/Opera.pm ↑ Summary lib/Bookmarks/Netscape.pm »
1 package Bookmarks::XML;
2 5 ▶use base 'Bookmarks::Parser';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
8 0 my ($class, %opts) = @_;
9  
10 # %opts = check_options(%opts);
11  
12 0 ▶ my $self = bless({%opts}, ref($class) || $class);
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
13 0 return $self;
14 }
15  
16 0 ▶sub parse_file {
Subroutine parse_file: not called CC=3 SCAR=24.8
Pod documented
17 0 my ($sel, $filename) = @_;
18  
19 0 ▶ return if (!$filename || !-e $filename);
Branch: 1 branch
BranchTrueFalseTotal
unless $filename and -e $filename 0 0 0
Condition0%0/3
$filename and -e $filename
!ll&&!rl&&r
000
MC/DC0%0/2
$filename and -e $filename
$filename -e $filename
Truth table0%0/3
A and B
A= $filenameB= -e $filename
ABresult
0X0
100
111
20  
21 0 my $bookmarks = XMLin($filename, ForceArray => ['folder']);
22  
23 }
24  
25 0 ▶sub get_header_as_string {
Subroutine get_header_as_string: not called CC=2 SCAR=17.9
Pod documented
26 0 my ($self) = @_;
27  
28 0 my $now = scalar localtime;
29 0 ▶ my $title = $self->{_title} || 'Bookmarks';
Condition0%0/2
$self->{'_title'} || 'Bookmarks'
l!l
00
MC/DC0%0/1
$self->{'_title'} || 'Bookmarks'
$self->{'_title'}
Truth table0%0/2
A
A= $self->{'_title'}
Aresult
11
00
30 0 my $header = << "XML";
31 <?xml version="1.0" encoding="UTF-8"?>
32 <!--
33 Bookmarks::XML internal format
34 Created on: $now
35  
36 -->
37 <bookmarks title="$title">
38 XML
39  
40 0 return $header;
41 }
42  
43 0 ▶sub get_item_as_string {
Subroutine get_item_as_string: not called CC=17 SCAR=57.2
Pod documented
44 0 my ($self, $item) = @_;
45  
46 0 ▶ if (!defined $item->{id} || !$self->{_items}{ $item->{id} }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $item->{"id"} and $self->{"_items"}{$item->{"id"}}) 0 0 0
Condition0%0/3
defined $item->{"id"} and $self->{"_items"}{$item->{"id"}}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $item->{"id"} and $self->{"_items"}{$item->{"id"}}
defined $item->{"id"} $self->{"_items"}{$item->{"id"}}
Truth table0%0/3
A and B
A= defined $item->{"id"}B= $self->{"_items"}{$item->{"id"}}
ABresult
0X0
100
111
47 0 warn "No such item in get_item_as_string";
48 0 return;
49 }
50  
51 0 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 0 ▶ $item->{order} || ''
Condition0%0/22
$item->{'id'} || 0
l!l
00
$item->{'url'} || ''
l!l
00
$item->{'name'} || ''
l!l
00
$item->{'visited'} || 0
l!l
00
$item->{'created'} || time
l!l
00
$item->{'modified'} || 0
l!l
00
$item->{'icon'} || ''
l!l
00
$item->{'description'} || ''
l!l
00
$item->{'expanded'} || ''
l!l
00
$item->{'trash'} || ''
l!l
00
$item->{'order'} || ''
l!l
00
MC/DC0%0/1
$item->{'id'} || 0
$item->{'id'}
MC/DC0%0/1
$item->{'url'} || ''
$item->{'url'}
MC/DC0%0/1
$item->{'name'} || ''
$item->{'name'}
MC/DC0%0/1
$item->{'visited'} || 0
$item->{'visited'}
MC/DC0%0/1
$item->{'created'} || time
$item->{'created'}
MC/DC0%0/1
$item->{'modified'} || 0
$item->{'modified'}
MC/DC0%0/1
$item->{'icon'} || ''
$item->{'icon'}
MC/DC0%0/1
$item->{'description'} || ''
$item->{'description'}
MC/DC0%0/1
$item->{'expanded'} || ''
$item->{'expanded'}
MC/DC0%0/1
$item->{'trash'} || ''
$item->{'trash'}
MC/DC0%0/1
$item->{'order'} || ''
$item->{'order'}
Truth table0%0/2
A
A= $item->{'id'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'url'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'name'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'visited'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'created'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'modified'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'icon'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'description'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'expanded'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'trash'}
Aresult
11
00
Truth table0%0/2
A
A= $item->{'order'}
Aresult
11
00
65 );
66  
67 0 ▶ if ($item->{type} eq 'folder') {
Branch: 2 branches
BranchTrueFalseTotal
if ($item->{'type'} eq 'folder') { } 0 0 0
elsif ($item->{'type'} eq 'url') { } 0 0 0
68 0 $string .= << "XML";
69 <folder id="$id" name="$name" created="$created" visited="$visited" icon="$icon" description="$desc" expanded="$expand" trash="$trash">
70 XML
71  
72 $string .= $self->get_item_as_string($self->{_items}{$_})
73 0 foreach (@{ $item->{children} });
74 0 $string .= " </folder>\n";
75 }
76 elsif ($item->{type} eq 'url') {
77 0 $string .= << "XML";
78 <bookmark id="$id" url="$url" name="$name" created="$created" visited="$visited" modified="$modified" icon="$icon" description="$desc" order="$order" />
79 XML
80  
81 }
82  
83 0 return $string;
84 }
85  
86 0 ▶sub get_footer_as_string {
Subroutine get_footer_as_string: not called CC=1 SCAR=6.9
Pod documented
87 0 my ($self) = @_;
88  
89 0 my $footer = << "XML";
90 </bookmarks>
91 XML
92  
93 0 return $footer;
94 }
95  
96 5 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<Bookmarks::Parser> documentation.
120 They are overridden because of the XML behaviour here.
121 Interface remains the same.
122  
123 =cut
« lib/Bookmarks/Opera.pm ↑ Summary lib/Bookmarks/Netscape.pm »