| 1 | # -*- cperl; cperl-indent-level: 4 -*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright (C) 2009-2021, Roland van Ipenburg | ||||||||||||||||||||||||||||||||||||||||||
| 3 | package HTML::Hyphenate v1.1.10; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use 5.016000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use charnames (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | #use Log::Log4perl qw(:resurrect :easy get_logger); | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use I18N::LangTags; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | ▶ | use Set::Scalar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use TeX::Hyphen; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use TeX::Hyphen::Pattern v1.1.8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use HTML::Hyphenate::DOM; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | ## no critic qw(ProhibitCallsToUnexportedSubs) | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | Readonly::Scalar my $EMPTY => q{}; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 12 | Readonly::Scalar my $DOT => q{.}; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | Readonly::Scalar my $SOFT_HYPHEN => charnames::string_vianame(q{SOFT HYPHEN}); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 12 | Readonly::Scalar my $CLASS_JOINER => q{, .}; # for CSS classnames | |||||||||||||||||||||||||||||||||||||||||
| 23 | 12 | Readonly::Scalar my $ONE_LEVEL_UP => -1; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 12 | Readonly::Scalar my $DOCTYPE => q{<!DOCTYPE html>}; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | Readonly::Hash my %DEFAULT => ( | |||||||||||||||||||||||||||||||||||||||||
| 27 | 'MIN_LENGTH' => 10, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 'MIN_PRE' => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 'MIN_POST' => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 'LANG' => q{en_us}, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 'INCLUDED' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # HTML %Text attributes <http://www.w3.org/TR/REC-html40/index/attributes.html> | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # HTML5 text attributes <https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes> | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 12 | my $text_attr = | |||||||||||||||||||||||||||||||||||||||||
| 37 | Set::Scalar->new(qw/abbr alt label list placeholder standby summary title/); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | ## no critic qw(ProhibitCallsToUnexportedSubs) | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 12 | Readonly::Hash my %LOG => ( | |||||||||||||||||||||||||||||||||||||||||
| 41 | 'TRAVERSE' => q{Traversing HTML element '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 'LANGUAGE_SET' => q{Language changed to '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 'PATTERN_FILE' => q{Using pattern file '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 'TEXT_NODE' => q{Text node value '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 'HYPHEN_TEXT' => q{Hyphenating text '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 'HYPHEN_WORD' => q{Hyphenating word '%s' to '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 'LOOKING_UP' => q{Looking up for %d class(es)}, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 'HTML_METHOD' => q{Using HTML passed to method '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 'HTML_PROPERTY' => q{Using HTML property '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 'NOT_HYPHEN' => q{No pattern found for '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 'TRY_SIMILAR' => q{Searching a pattern similar to the unmatched '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 'SIMILARITY' => q{Similarity of candidate '%s' is %i}, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 'REGISTER' => q{Registering TeX::Hyphen object for label '%s'}, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 'NO_CLASSES' => q{No classes defined, so not check for them}, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | ## no critic qw(ProhibitCommentedOutCode) | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ###l4p Log::Log4perl->easy_init( { 'level' => $DEBUG, 'utf8' => 1 } ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ###l4p my $log = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | ## no critic qw(ProhibitHashBarewords ProhibitCallsToUnexportedSubs ProhibitCallsToUndeclaredSubs) | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 12 | has html => ( is => 'rw', isa => 'Str' ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 412 | ▶ | after 'html' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 412 | my ( $self, $html ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 412 | ▶ | if ( defined $html ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | ## no critic qw(ProhibitUnusedCapture) | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 138 | ▶ | if ( $self->html =~ m{^(?<doctype>\s*\Q$DOCTYPE\E)(?<html>.*)}gismx ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 3 | $self->html( ${+}{html} ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | $self->_doctype( ${+}{doctype} ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 135 | $self->_doctype($EMPTY); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 12 | has style => ( is => 'rw', isa => 'Str' ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | has min_length => | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 12 | ( is => 'rw', isa => 'Int', default => $DEFAULT{'MIN_LENGTH'} ); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 12 | has min_pre => ( is => 'rw', isa => 'Int', default => $DEFAULT{'MIN_PRE'} ); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 12 | has min_post => ( is => 'rw', isa => 'Int', default => $DEFAULT{'MIN_POST'} ); | |||||||||||||||||||||||||||||||||||||||||
| 84 | 12 | has default_lang => ( is => 'rw', isa => 'Str', default => $DEFAULT{'LANG'} ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | has default_included => | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 12 | ( is => 'rw', isa => 'Int', default => $DEFAULT{'INCLUDED'} ); | |||||||||||||||||||||||||||||||||||||||||
| 87 | has classes_included => | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 12 | ▶ | ( is => 'rw', isa => 'ArrayRef', default => sub { [] } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | has classes_excluded => | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 12 | ▶ | ( is => 'rw', isa => 'ArrayRef', default => sub { [] } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 169 | ▶ | after 'classes_included' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 169 | my ( $self, $ar ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 169 | ▶ | if ( defined $ar ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 17 | $self->_classes( | |||||||||||||||||||||||||||||||||||||||||
| 95 | ( scalar $self->classes_excluded + scalar $self->classes_included ) | ||||||||||||||||||||||||||||||||||||||||||
| 96 | > 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 169 | ▶ | after 'classes_excluded' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 169 | my ( $self, $ar ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 169 | ▶ | if ( defined $ar ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 17 | $self->_classes( | |||||||||||||||||||||||||||||||||||||||||
| 104 | ( scalar $self->classes_excluded + scalar $self->classes_included ) | ||||||||||||||||||||||||||||||||||||||||||
| 105 | > 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 12 | ▶ | has _hyphenators => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 12 | has _lang => ( is => 'rw', isa => 'Str' ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | 12 | has _doctype => ( is => 'rw', isa => 'Str' ); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 12 | has _dom => ( is => 'rw', isa => 'HTML::Hyphenate::DOM' ); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 12 | ▶ | has _scope_is_root => ( is => 'rw', isa => 'Bool', default => sub { 0 } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 12 | ▶ | has _classes => ( is => 'rw', isa => 'Bool', default => sub { 0 } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | ## no critic qw(ProhibitCallsToUnexportedSubs) | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 12 | Readonly::Scalar my $LANG => q{lang}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 12 | Readonly::Scalar my $HTML => q{html}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 12 | Readonly::Scalar my $TEXT => q{text}; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | Readonly::Scalar my $TAG => q{tag}; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 12 | Readonly::Scalar my $RAW => q{raw}; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 12 | Readonly::Scalar my $PRE => q{pre}; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 12 | Readonly::Scalar my $CLASS => q{class}; | |||||||||||||||||||||||||||||||||||||||||
| 125 | ## no critic qw(RequireDotMatchAnything RequireExtendedFormatting RequireLineBoundaryMatching) | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 12 | Readonly::Scalar my $NONSPACE => qr{\S+}; | |||||||||||||||||||||||||||||||||||||||||
| 127 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 135 | ▶ | sub hyphenated { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hyphenated: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 135 | my ( $self, $html ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 135 | ▶ | if ( defined $html ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | ###l4p $log->debug( sprintf $LOG{'HTML_METHOD'}, $html ); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 134 | $self->html($html); | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | ###l4p $log->debug( sprintf $LOG{'HTML_PROPERTY'}, $self->html ); | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 135 | $self->_reset_dom; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 135 | $self->_dom->parse( $self->html ); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 135 | $self->_traverse_dom( $self->_dom->root ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 135 | return $self->_clean_html(); | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | ▶ | sub register_tex_hyphen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_tex_hyphen: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | my ( $self, $label, $tex ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $label and builtin::blessed($tex) and $tex->isa("TeX::Hyphen")
defined $label and builtin::blessed($tex)
MC/DC100%3/3
defined $label and builtin::blessed($tex) and $tex->isa("TeX::Hyphen")
defined $label
builtin::blessed($tex)
$tex->isa("TeX::Hyphen")
Truth table100%4/4
A and B and C
A= defined $labelB= builtin::blessed($tex)C= $tex->isa("TeX::Hyphen")
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | defined $label | ||||||||||||||||||||||||||||||||||||||||||
| 149 | ## no critic qw(ProhibitCallsToUndeclaredSubs) | ||||||||||||||||||||||||||||||||||||||||||
| 150 | && blessed $tex | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 152 | && $tex->isa('TeX::Hyphen') | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | my $cache = $self->_hyphenators; | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | ###l4p $log->debug( sprintf $LOG{'REGISTER'}, $label ); | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | ${$cache}{$label} = $tex; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | $self->_hyphenators($cache); | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 606 | ▶ | sub _traverse_dom { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_traverse_dom: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 606 | my ( $self, $node ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 606 | ▶ | if ( $self->_hyphenable($node) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 549 | my $type = $node->type; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 549 | ▶ | if ( $TAG eq $type ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | ###l4p $log->debug( sprintf $LOG{'TRAVERSE'}, $node->tag ); | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 191 | $self->_configure_lang($node); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 191 | ▶ | while ( my ( $k, $v ) = each %{ $node->attr } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 142 | ▶ | if ( $text_attr->has($k) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$text_attr->has($k) and length $v >= $self->min_length
MC/DC100%2/2
$text_attr->has($k) and length $v >= $self->min_length
$text_attr->has($k)
length $v >= $self->min_length
Truth table100%3/3
A and B
A= $text_attr->has($k)B= length $v >= $self->min_length
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | && length $v >= $self->min_length ) | ||||||||||||||||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 10 | $node->attr( $k, $self->_hyphen($v) ); | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | ▶ | elsif ( $TEXT eq $type || $RAW eq $type ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$TEXT eq $type or $RAW eq $type
MC/DC50%1/2
$TEXT eq $type or $RAW eq $type
$TEXT eq $type
$RAW eq $type
Truth table66%2/3
A or B
A= $TEXT eq $typeB= $RAW eq $type
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 231 | my $string = $node->to_string; | |||||||||||||||||||||||||||||||||||||||||
| 182 | ###l4p $log->trace( sprintf $LOG{'TEXT_NODE'}, $string ); | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 231 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $string >= $self->min_length and $string =~ /$NONSPACE/ux
MC/DC100%2/2
length $string >= $self->min_length and $string =~ /$NONSPACE/ux
length $string >= $self->min_length
$string =~ /$NONSPACE/ux
Truth table100%3/3
A and B
A= length $string >= $self->min_lengthB= $string =~ /$NONSPACE/ux
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | length $string >= $self->min_length | ||||||||||||||||||||||||||||||||||||||||||
| 185 | ## no critic qw(RequireDotMatchAnything RequireLineBoundaryMatching) | ||||||||||||||||||||||||||||||||||||||||||
| 186 | && $string =~ m{$NONSPACE}x | ||||||||||||||||||||||||||||||||||||||||||
| 187 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 188 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 150 | $self->_configure_lang($node); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 150 | my $hyphened = $self->_hyphen($string); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 150 | $node->replace($hyphened); | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 231 | return; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 375 | for my $child ( $node->child_nodes->each ) { | |||||||||||||||||||||||||||||||||||||||||
| 198 | 471 | $self->_traverse_dom($child); | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 375 | return; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 135 | ▶ | sub _clean_html { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clean_html: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 135 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 135 | my $html = $self->_dom->to_string(); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 135 | $self->_reset_dom; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 135 | ▶ | if ( $EMPTY ne $self->_doctype ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | $html = $self->_doctype . $html; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 135 | return $html; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 160 | ▶ | sub _hyphen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hyphen: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 160 | my ( $self, $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | ###l4p $log->debug( sprintf $LOG{'HYPHEN_TEXT'}, $text ); | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 160 | $text =~ s/(\w{@{[$self->min_length]},})/$self->_hyphen_word($1)/xsmeg; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 160 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 182 | ▶ | sub _hyphen_word { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hyphen_word: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 182 | my ( $self, $word ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 182 | ▶ | if ( defined $self->_hyphenators->{ $self->_lang } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | ###l4p $log->debug( sprintf $LOG{'HYPHEN_WORD'}, | ||||||||||||||||||||||||||||||||||||||||||
| 226 | ###l4p $word, $self->_hyphenators->{ $self->_lang }->visualize($word) ); | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 181 | my $number = 0; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 181 | foreach | |||||||||||||||||||||||||||||||||||||||||
| 229 | my $pos ( $self->_hyphenators->{ $self->_lang }->hyphenate($word) ) | ||||||||||||||||||||||||||||||||||||||||||
| 230 | { | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 1199 | substr $word, $pos + $number, 0, $SOFT_HYPHEN; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 1199 | $number += length $SOFT_HYPHEN; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | ###l4p $log->warn( sprintf $LOG{'NOT_HYPHEN'}, $self->_lang ); | ||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 182 | return $word; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | ## no critic qw(RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 680 | ▶ | sub __lang_attr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__lang_attr: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 680 | ▶ | if ( $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 578 | ▶ | return $_[0]->attr($LANG) || $_[0]->attr(qq{xml:$LANG}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_[0]->attr($LANG) || $_[0]->attr("xml:$LANG")
MC/DC100%2/2
$_[0]->attr($LANG) || $_[0]->attr("xml:$LANG")
$_[0]->attr($LANG)
$_[0]->attr("xml:$LANG")
Truth table100%3/3
A || B
A= $_[0]->attr($LANG)B= $_[0]->attr("xml:$LANG")
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 102 | return; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 341 | ▶ | sub _configure_lang { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_configure_lang: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 341 | my ( $self, $element ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 341 | my $lang = __lang_attr($element); | |||||||||||||||||||||||||||||||||||||||||
| 255 | 341 | ▶ | if ( defined $lang ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 106 | $self->_scope_is_root( $HTML eq $element->tag ); | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 341 | ▶ | if ( !defined $lang ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 235 | $lang = __lang_attr( $element->parent ); | |||||||||||||||||||||||||||||||||||||||||
| 260 | 235 | ▶ | if ( defined $lang ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 115 | $self->_scope_is_root( $HTML eq $element->parent->tag ); | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 341 | ▶ | if ( !defined $lang ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | # If the scope was already set by the root element we don't have to | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # check if it has gone out of scope because we never leave the root | ||||||||||||||||||||||||||||||||||||||||||
| 268 | # scope: | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 120 | ▶ | if ( !$self->_scope_is_root ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 104 | my $recent = $element->ancestors(qq{[$LANG]})->first(); | |||||||||||||||||||||||||||||||||||||||||
| 271 | 104 | ▶ | $self->_scope_is_root( $recent && $HTML eq $recent->tag ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$recent && $HTML eq $recent->tag
MC/DC100%2/2
$recent && $HTML eq $recent->tag
$recent
$HTML eq $recent->tag
Truth table100%3/3
A && B
A= $recentB= $HTML eq $recent->tag
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 104 | $lang = __lang_attr($recent); | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 16 | $lang = $self->_lang; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 341 | ▶ | if ( !defined $lang ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 102 | $lang = $self->default_lang; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 341 | ▶ | if ( !defined $self->_lang || $lang ne $self->_lang ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $self->_lang or $lang ne $self->_lang
MC/DC100%2/2
not defined $self->_lang or $lang ne $self->_lang
not defined $self->_lang
$lang ne $self->_lang
Truth table100%3/3
not(A) or B
A= not defined $self->_langB= $lang ne $self->_lang
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 106 | $self->_lang($lang); | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | ###l4p $log->debug( sprintf $LOG{'LANGUAGE_SET'}, $lang ); | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 106 | ▶ | if ( !exists $self->_hyphenators->{$lang} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 78 | $self->_add_tex_hyphen_to_cache(); | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 341 | return; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 78 | ▶ | sub _add_tex_hyphen_to_cache { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_tex_hyphen_to_cache: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 78 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 78 | my $thp = TeX::Hyphen::Pattern->new(); | |||||||||||||||||||||||||||||||||||||||||
| 295 | 78 | my $pat = $self->_lang; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 78 | $thp->label($pat); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 78 | my $file = $thp->filename; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 78 | ▶ | if ( !defined $file ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | ###l4p $log->debug( sprintf $LOG{'TRY_SIMILAR'}, $pat ); | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 4 | my $max_sim = 0; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | for my $tag ( $thp->available() ) { | |||||||||||||||||||||||||||||||||||||||||
| 302 | 584 | $tag =~ s{.*::}{}msx; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 584 | $tag =~ s{[_]}{-}msx; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 584 | my $sim = | |||||||||||||||||||||||||||||||||||||||||
| 305 | I18N::LangTags::similarity_language_tag( $tag, $self->_lang ); | ||||||||||||||||||||||||||||||||||||||||||
| 306 | ###l4p $log->debug( sprintf $LOG{'SIMILARITY'}, $tag, $sim ); | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 584 | ▶ | if ( $sim > $max_sim ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 4 | $pat = $tag; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 4 | $max_sim = $sim; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 4 | ▶ | if ( $max_sim > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 3 | $thp->label($pat); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 3 | $file = $thp->filename; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 78 | ▶ | if ( defined $file ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | ###l4p $log->debug( sprintf $LOG{'PATTERN_FILE'}, $file ); | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 77 | my $cache = $self->_hyphenators; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 77 | ${$cache}{ $self->_lang } = TeX::Hyphen->new( | |||||||||||||||||||||||||||||||||||||||||
| 322 | q{file} => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 323 | q{leftmin} => $self->min_pre, | ||||||||||||||||||||||||||||||||||||||||||
| 324 | q{rightmin} => $self->min_post, | ||||||||||||||||||||||||||||||||||||||||||
| 325 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 77 | $self->_hyphenators($cache); | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 78 | return; | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 118 | ▶ | sub _hyphenable_by_class { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hyphenable_by_class: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 118 | my ( $self, $node ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 118 | my $included_level = $ONE_LEVEL_UP; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 118 | my $excluded_level = $ONE_LEVEL_UP; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 118 | ▶ | $self->default_included && $excluded_level--; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 118 | ▶ | $self->default_included || $included_level--; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 118 | $included_level = | |||||||||||||||||||||||||||||||||||||||||
| 339 | $self->_get_nearest_ancestor_level_by_classname( $node, | ||||||||||||||||||||||||||||||||||||||||||
| 340 | $self->classes_included, $included_level ); | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 118 | $excluded_level = | |||||||||||||||||||||||||||||||||||||||||
| 342 | $self->_get_nearest_ancestor_level_by_classname( $node, | ||||||||||||||||||||||||||||||||||||||||||
| 343 | $self->classes_excluded, $excluded_level ); | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 118 | ▶ | if ( $included_level == $excluded_level ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 4 | return $self->default_included; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 114 | return !( $excluded_level > $included_level ); | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 606 | ▶ | sub __parent_is_pre { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__parent_is_pre: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 606 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 606 | my $parent = $node->parent; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 606 | ▶ | return defined $parent | ||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
defined $parent && ($parent->tag || $EMPTY) eq $PRE
$parent->tag || $EMPTY
MC/DC66%2/3
defined $parent && ($parent->tag || $EMPTY) eq $PRE
defined $parent
$parent->tag
$EMPTY
Truth table75%3/4
A && B || C
A= defined $parentB= $parent->tagC= $EMPTY
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | && ( ( $parent->tag || $EMPTY ) eq $PRE ); | ||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 606 | ▶ | sub _hyphenable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hyphenable: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 606 | my ( $self, $node ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | ###l4p $self->_classes || $log->debug( $LOG{'NO_CLASSES'} ); | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 606 | ▶ | return !( __parent_is_pre($node) | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
__parent_is_pre($node) || $self->_classes && !$self->_hyphenable_by_class($node)
$self->_classes and not $self->_hyphenable_by_class($node)
MC/DC100%3/3
__parent_is_pre($node) || $self->_classes && !$self->_hyphenable_by_class($node)
__parent_is_pre($node)
$self->_classes
not $self->_hyphenable_by_class($node)
Truth table100%4/4
A || B and not(C)
A= __parent_is_pre($node)B= $self->_classesC= not $self->_hyphenable_by_class($node)
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | || ( $self->_classes && !$self->_hyphenable_by_class($node) ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 236 | ▶ | sub _get_nearest_ancestor_level_by_classname { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_nearest_ancestor_level_by_classname: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 236 | my ( $self, $node, $ar_classnames, $level ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 236 | my $classnames = Set::Scalar->new( @{$ar_classnames} ); | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | ###l4p $log->debug( sprintf $LOG{'LOOKING_UP'}, $classnames->size ); | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 236 | ▶ | if ( !$classnames->is_empty | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $classnames->is_empty and $node->ancestors->size
MC/DC100%2/2
not $classnames->is_empty and $node->ancestors->size
not $classnames->is_empty
$node->ancestors->size
Truth table100%3/3
not(A) and B
A= not $classnames->is_emptyB= $node->ancestors->size
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | && ( $node->ancestors->size ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 372 | { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 144 | my $selector = $DOT . join $CLASS_JOINER, $classnames->members; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 144 | my $nearest = $node->ancestors($selector)->first; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 144 | ▶ | if ($nearest) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 64 | return $nearest->ancestors->size; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 172 | return $level; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 270 | ▶ | sub _reset_dom { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reset_dom: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 270 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 270 | my $dom = HTML::Hyphenate::DOM->new(); | |||||||||||||||||||||||||||||||||||||||||
| 385 | 270 | $self->_dom($dom); | |||||||||||||||||||||||||||||||||||||||||
| 386 | 270 | return; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | __END__ | ||||||||||||||||||||||||||||||||||||||||||