line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FB3; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
103359
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
698
|
use utf8; |
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
685
|
use OPC; |
|
1
|
|
|
|
|
140526
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
8
|
1
|
|
|
1
|
|
576
|
use File::ShareDir qw/dist_dir/; |
|
1
|
|
|
|
|
26219
|
|
|
1
|
|
|
|
|
93
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.17'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
FB3 - API for manipulating FB3 files |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use FB3; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# load FB3 from file |
21
|
|
|
|
|
|
|
my $FB3 = FB3->new( from_zip => 'path/to/file.fb3'); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# or load FB3 from directory where it had been unpacked |
24
|
|
|
|
|
|
|
my $FB3 = FB3->new( from_dir => 'path/to/unpacked_fb3_dir'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# navigate through FB3 and read XML content of it's main parts |
27
|
|
|
|
|
|
|
$Meta = $FB3->Meta; |
28
|
|
|
|
|
|
|
$MetaXML = $Meta->Content; |
29
|
|
|
|
|
|
|
$BodyXML = $FB3->Body->Content; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# get path to cover |
32
|
|
|
|
|
|
|
$PathToCover = $FB3->Cover->PhysicalName; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 AUTHOR |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Litres.ru Team |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use constant { |
41
|
1
|
|
|
|
|
632
|
RELATION_TYPE_CORE_PROP => |
42
|
|
|
|
|
|
|
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties' |
43
|
1
|
|
|
1
|
|
10
|
}; |
|
1
|
|
|
|
|
3
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Returns path to FB3 schemas common directory |
46
|
|
|
|
|
|
|
sub SchemasDirPath { |
47
|
0
|
|
|
0
|
0
|
|
return dist_dir('FB3'); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Returns path to requested FB3 scheme |
51
|
|
|
|
|
|
|
sub SchemaPath { |
52
|
0
|
|
|
0
|
0
|
|
my $SchemaName = shift; |
53
|
0
|
|
|
|
|
|
my $SchemaPath = FB3::SchemasDirPath().'/'.$SchemaName; |
54
|
0
|
0
|
|
|
|
|
die "$SchemaName doesn't exist" unless -e $SchemaPath; |
55
|
0
|
|
|
|
|
|
return $SchemaPath; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub new { |
59
|
0
|
|
|
0
|
0
|
|
my( $Class, %Params ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $OPCPackage; |
62
|
0
|
0
|
0
|
|
|
|
if( exists $Params{from_zip} && defined $Params{from_zip} ) { |
|
|
0
|
0
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$OPCPackage = OPC->FromZip( $Params{from_zip} ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} elsif( exists $Params{from_dir} && defined $Params{from_dir} ) { |
66
|
0
|
|
|
|
|
|
$OPCPackage = OPC->FromDir( $Params{from_dir} ); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
|
|
|
|
|
Carp::confess 'Must pass from_zip or from_dir argument'; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $self = { |
73
|
|
|
|
|
|
|
opc => $OPCPackage, |
74
|
|
|
|
|
|
|
root => $OPCPackage->Root, |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return bless $self, $Class; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub Cover { |
81
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
82
|
0
|
|
|
|
|
|
return $self->{root}->Thumbnail; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub Meta { |
86
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
87
|
0
|
|
|
|
|
|
return $self->{root}->RelatedPart( type => 'http://www.fictionbook.org/FictionBook3/relationships/Book' ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub Body { |
91
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
92
|
0
|
|
|
|
|
|
return $self->Meta->RelatedPart( type => 'http://www.fictionbook.org/FictionBook3/relationships/body' ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub Root { |
96
|
0
|
|
|
0
|
0
|
|
return shift->{root}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub Part { |
100
|
0
|
|
|
0
|
0
|
|
my( $self, $PartName ) = @_; |
101
|
0
|
|
|
|
|
|
return $self->{opc}->Part( name => $PartName ) |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub HasPart { |
105
|
0
|
|
|
0
|
0
|
|
my( $self, $PartName ) = @_; |
106
|
0
|
|
|
|
|
|
return $self->{opc}->HasPart( $PartName ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub SetPartContents { |
110
|
0
|
|
|
0
|
0
|
|
my( $self, $PartName, $PartContents ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$self->{opc}->SetContents( $PartName, $PartContents ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub DirPath { |
116
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
117
|
0
|
0
|
|
|
|
|
if ($self->{opc}->{_is_zip}) { |
118
|
0
|
|
|
|
|
|
die "FB3 is ZIP archive, not directory"; |
119
|
|
|
|
|
|
|
} else { |
120
|
0
|
|
|
|
|
|
return $self->{opc}->{_physical}; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Copyright (C) 2018 Litres.ru |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The GNU Lesser General Public License version 3.0 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
FB3 is free software: you can redistribute it and/or modify it |
131
|
|
|
|
|
|
|
under the terms of the GNU Lesser General Public License as published by |
132
|
|
|
|
|
|
|
the Free Software Foundation, either version 3.0 of the License. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
FB3 is distributed in the hope that it will be useful, but |
135
|
|
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
136
|
|
|
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
137
|
|
|
|
|
|
|
License for more details. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Full text of License L. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |