Generator/EBook.pm

filter: Statementstmt 55.5% 45 / 81 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 15 / 20 Podpod 0.0% 0 / 5 totaltotal 51.2% 60 / 117 CC 6 SCAR 19.9
CC
6
Cov
50%
init
30.0
writeEBook
6.0
new
2.0
CRAP 7.3
« Generator/Analyser.pm ↑ Summary Generator/Exporter/Text.pm »
1 package EBook::Generator::EBook;
2  
3 1 ▶use 5.008009;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use XML::LibXML::XPathContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use EBook::Generator::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use EBook::Generator::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use EBook::Generator::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use EBook::Generator::Analyser;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 sub new
22 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
23 0 my ($class, @args) = @_;
24 0 my $self = bless {}, $class;
25 0 return $self->init(@args);
26 }
27  
28 sub init
29 0 ▶{
Subroutine init: not called CC=5 SCAR=34.0
Pod undocumented
30 0 my ($self, $url, %options) = @_;
31
32 #--- user configurable options ---
33
34 $self->{'options'} = {
35 'debug' => 0,
36  
37 'min-img-width' => 100,
38 'min-img-height' => 80,
39
40 # identify advert images using the aspect ratio of image, e.g.
41 # 1200 x 200 -> 1200/200 = 6 BAD!
42 # 600 x 400 -> 600/400 = 1.5 OK!
43 'image-max-length-aspect-ratio' => 3,
44
45 'use-color-images' => 0,
46  
47 # currently only recognized for format XHTML
48 'embed-images' => 1,
49 'epub' => 0, # if the xhtml should be wrapped inside an EPUB document
50  
51 # only used for format PDF
52 0 ▶ 'local-tex-tree-path' => (exists $ENV{'HOME'} ? $ENV{'HOME'} : '/tmp').'/textree',
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{'HOME'} ? : 0 0 0
53 };
54
55 # parse user options
56 0 foreach my $key (keys %{$self->{'options'}}) {
57 $self->{'options'}->{$key} = $options{$key}
58 if exists($options{$key}) &&
59 0 ▶ ref($options{$key}) eq ref($self->{'options'}->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{$key} and ref $options{$key} eq ref $self->{"options"}{$key} 0 0 0
Condition0%0/3
exists $options{$key} and ref $options{$key} eq ref $self->{"options"}{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $options{$key} and ref $options{$key} eq ref $self->{"options"}{$key}
exists $options{$key} ref $options{$key} eq ref $self->{"options"}{$key}
Truth table0%0/3
A and B
A= exists $options{$key}B= ref $options{$key} eq ref $self->{"options"}{$key}
ABresult
0X0
100
111
60 }
61  
62 #--- system options ---
63  
64 # web browser
65 0 $self->{'browser'} = LWP::UserAgent->new();
66 0 $self->{'browser'}->timeout(10);
67  
68 # create xml parser
69 0 $self->{'xml-parser'} = XML::LibXML->new();
70 0 $self->{'xml-parser'}->recover(2);
71
72 0 $self->{'url'} = $url;
73 0 $self->{'log'} = [];
74
75 $self->{'reader'} =
76 0 EBook::Generator::Reader->new($self->{'browser'}, $self->{'log'});
77
78 $self->{'parser'} =
79 0 EBook::Generator::Parser->new($self->{'browser'}, $self->{'xml-parser'}, $self->{'log'});
80  
81 $self->{'analyser'} =
82 0 EBook::Generator::Analyser->new($self->{'log'});
83  
84 0 $self->readSource();
85
86 0 return $self;
87 }
88  
89 sub readSource
90 0 ▶{
Subroutine readSource: not called CC=1 SCAR=6.9
Pod undocumented
91 0 my ($self) = @_;
92  
93 0 @{$self->{'log'}} = ();
94
95 # fetch content html
96 0 my $raw = $self->{'reader'}->getContent($self->{'url'});
97
98 # parse content into semantic datastructure structure
99 0 my @result = $self->{'parser'}->parseContent($raw, $self->{'url'}, $self->{'options'});
100 0 $self->{'meta'} = $result[0];
101 0 $self->{'data'} = $result[1];
102
103 #print Dumper($self->{'data'}->toString());
104 #exit;
105
106 0 return $self;
107 }
108  
109 sub writeEBook
110 0 ▶{
Subroutine writeEBook: not called CC=2 SCAR=17.9
Pod undocumented
111 0 my ($self, $format) = @_;
112 0 ▶ $format = 'pdf' unless defined $format;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $format 0 0 0
113
114 # analyse content
115 0 $self->{'analyser'}->analyseContent($self);
116
117 0 my $exporter = EBook::Generator::Exporter->new($self->{'browser'}, $self->{'log'});
118 0 my $filename = $exporter->writeEBook($self, $format, $self->{'options'});
119
120 0 $self->{'parser'}->cleanup();
121 0 return $filename;
122 }
123  
124 sub getLog
125 0 ▶{
Subroutine getLog: not called CC=1 SCAR=6.9
Pod undocumented
126 0 my ($self) = @_;
127 0 return $self->{'log'};
128 }
129  
130 1 1;
« Generator/Analyser.pm ↑ Summary Generator/Exporter/Text.pm »