| 1 | package EBook::Generator::Analyser; | ||||||||||
| 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 Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | our $VERSION = '0.01'; | |||||||||
| 10 | |||||||||||
| 11 | sub new | ||||||||||
| 12 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 13 | 0 | my ($class, @args) = @_; | |||||||||
| 14 | 0 | my $self = bless {}, $class; | |||||||||
| 15 | 0 | return $self->init(@args); | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | sub init | ||||||||||
| 19 | 0 | ▶ | { | ||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 20 | 0 | my ($self, $log) = @_; | |||||||||
| 21 | 0 | $self->{'log'} = $log; | |||||||||
| 22 | 0 | return $self; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | sub analyseContent | ||||||||||
| 26 | 0 | ▶ | { | ||||||||
|
Subroutine
analyseContent: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 27 | 0 | my ($self, $ebook) = @_; | |||||||||
| 28 | 0 | $self->{'options'} = $ebook->{'options'}; | |||||||||
| 29 | #push @{$self->{'log'}}, Dumper($ebook->{'data'}); | ||||||||||
| 30 | 0 | my @newnodes = $self->analyse_nodes($ebook->{'data'}); | |||||||||
| 31 | 0 | $ebook->{'data'} = $newnodes[0]; | |||||||||
| 32 | 0 | return 1; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | sub analyse_nodes | ||||||||||
| 36 | 0 | ▶ | { | ||||||||
|
Subroutine
analyse_nodes: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 37 | 0 | my ($self, @nodes) = @_; | |||||||||
| 38 | |||||||||||
| 39 | my %handlers = ( | ||||||||||
| 40 | 0 | ▶ | 'document' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 41 | 0 | my ($self, $node) = @_; | |||||||||
| 42 | 0 | my ($type, $opts, @subnodes) = @{$node}; | |||||||||
| 43 | 0 | return [$type, $opts, $self->analyse_nodes(@subnodes)]; | |||||||||
| 44 | }, | ||||||||||
| 45 | 0 | ▶ | 'paragraph' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 46 | 0 | my ($self, $node) = @_; | |||||||||
| 47 | 0 | my ($type, $opts, @subnodes) = @{$node}; | |||||||||
| 48 | 0 | my @newsubnodes = $self->analyse_nodes(@subnodes); | |||||||||
| 49 | 0 | ▶ | return () if scalar @newsubnodes == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | return [$type, $opts, @newsubnodes]; | |||||||||
| 51 | }, | ||||||||||
| 52 | 0 | ▶ | 'headline' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 53 | 0 | my ($self, $node) = @_; | |||||||||
| 54 | 0 | my ($type, $opts, @subnodes) = @{$node}; | |||||||||
| 55 | 0 | my @newsubnodes = $self->analyse_nodes(@subnodes); | |||||||||
| 56 | 0 | ▶ | return () if scalar @newsubnodes == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | return [$type, $opts, @newsubnodes]; | |||||||||
| 58 | }, | ||||||||||
| 59 | 0 | ▶ | 'text' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 60 | 0 | my ($self, $node) = @_; | |||||||||
| 61 | 0 | my ($type, $opts, @subnodes) = @{$node}; | |||||||||
| 62 | 0 | my @newsubnodes = $self->analyse_nodes(@subnodes); | |||||||||
| 63 | 0 | ▶ | return () if scalar @newsubnodes == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | return [$type, $opts, @newsubnodes]; | |||||||||
| 65 | }, | ||||||||||
| 66 | 0 | ▶ | 'link' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 67 | 0 | my ($self, $node) = @_; | |||||||||
| 68 | 0 | my ($type, $opts, @subnodes) = @{$node}; | |||||||||
| 69 | 0 | my @newsubnodes = $self->analyse_nodes(@subnodes); | |||||||||
| 70 | 0 | ▶ | return () if scalar @newsubnodes == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | return [$type, $opts, @newsubnodes]; | |||||||||
| 72 | }, | ||||||||||
| 73 | 0 | ▶ | 'media' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 74 | 0 | my ($self, $node) = @_; | |||||||||
| 75 | 0 | my ($type, $opts, @subnodes) = @{$node}; | |||||||||
| 76 | 0 | my @newsubnodes = $self->analyse_nodes(@subnodes); | |||||||||
| 77 | 0 | return [$type, $opts, @newsubnodes]; | |||||||||
| 78 | }, | ||||||||||
| 79 | 0 | ▶ | 'list' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 80 | 0 | my ($self, $node) = @_; | |||||||||
| 81 | 0 | my ($type, $opts, @subnodes) = @{$node}; | |||||||||
| 82 | 0 | my @newsubnodes = $self->analyse_nodes(@subnodes); | |||||||||
| 83 | 0 | ▶ | return () if scalar @newsubnodes == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | return [$type, $opts, @newsubnodes]; | |||||||||
| 85 | }, | ||||||||||
| 86 | 0 | ▶ | 'preformatted' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 87 | 0 | my ($self, $node) = @_; | |||||||||
| 88 | 0 | my ($type, $opts, @subnodes) = @{$node}; | |||||||||
| 89 | 0 | my @newsubnodes = $self->analyse_nodes(@subnodes); | |||||||||
| 90 | 0 | ▶ | return () if scalar @newsubnodes == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | return [$type, $opts, @newsubnodes]; | |||||||||
| 92 | }, | ||||||||||
| 93 | 0 | ▶ | 'quote' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 94 | 0 | my ($self, $node) = @_; | |||||||||
| 95 | 0 | my ($type, $opts, @subnodes) = @{$node}; | |||||||||
| 96 | 0 | my @newsubnodes = $self->analyse_nodes(@subnodes); | |||||||||
| 97 | 0 | ▶ | return () if scalar @newsubnodes == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | return [$type, $opts, @newsubnodes]; | |||||||||
| 99 | }, | ||||||||||
| 100 | 0 | ); | |||||||||
| 101 | |||||||||||
| 102 | 0 | my @newnodes = (); | |||||||||
| 103 | 0 | foreach my $node (@nodes) { | |||||||||
| 104 | 0 | ▶ | if (ref $node) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | my $type = $node->[0]; | |||||||||
| 106 | 0 | ▶ | if (exists $handlers{$type}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | 0 | push @newnodes, $handlers{$type}->($self, $node) | |||||||||
| 108 | } else { | ||||||||||
| 109 | # push it anyway, so we don't forget any content | ||||||||||
| 110 | 0 | push @newnodes, $node; | |||||||||
| 111 | } | ||||||||||
| 112 | } | ||||||||||
| 113 | else { | ||||||||||
| 114 | # cleanup text node | ||||||||||
| 115 | 0 | $node =~ s/^[\s\t\n\r]*//img; | |||||||||
| 116 | 0 | $node =~ s/[\s\t\n\r]*$//img; | |||||||||
| 117 | 0 | ▶ | push @newnodes, $node | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | if length $node; | ||||||||||
| 119 | } | ||||||||||
| 120 | } | ||||||||||
| 121 | 0 | return @newnodes; | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 1 | 1; | |||||||||
| 125 | __END__ | ||||||||||