| 1 | package HTML::Widgets::NavMenu::Url; | ||||||||||||||||||||||||||||||||
| 2 | 16 | $HTML::Widgets::NavMenu::Url::VERSION = '1.0902'; | |||||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use parent 'HTML::Widgets::NavMenu::Object'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 16 | __PACKAGE__->mk_acc_ref( | |||||||||||||||||||||||||||||||
| 9 | [ | ||||||||||||||||||||||||||||||||
| 10 | qw( | ||||||||||||||||||||||||||||||||
| 11 | _url | ||||||||||||||||||||||||||||||||
| 12 | _is_dir | ||||||||||||||||||||||||||||||||
| 13 | _mode | ||||||||||||||||||||||||||||||||
| 14 | ) | ||||||||||||||||||||||||||||||||
| 15 | ] | ||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | sub _init | ||||||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||||||
| 21 | 821 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 821 | my ( $url, $is_dir, $mode ) = @_; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | # TODO - extract a method. | ||||||||||||||||||||||||||||||||
| 26 | 821 | ▶ | $self->_url( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | ( ref($url) eq "ARRAY" ) | ||||||||||||||||||||||||||||||||
| 28 | ? [@$url] | ||||||||||||||||||||||||||||||||
| 29 | : [ split( /\//, $url ) ] | ||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 821 | ▶ | $self->_is_dir( $is_dir || 0 ); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$is_dir || 0
MC/DC100%1/1
$is_dir || 0
$is_dir
Truth table100%2/2
A
A= $is_dir
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 821 | ▶ | $self->_mode( $mode || 'server' ); | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$mode || 'server'
MC/DC100%1/1
$mode || 'server'
$mode
Truth table100%2/2
A
A= $mode
| |||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 821 | return 0; | |||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | sub _get_url | ||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||
| 41 | 821 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_get_url: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 821 | return [ @{ $self->_url() } ]; | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | sub _get_relative_url | ||||||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||||||
| 48 | 410 | ▶ | my $base = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_get_relative_url: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 410 | my $url = $base->_get_url_worker(@_); | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 408 | ▶ | return ( ( $url eq "" ) ? "./" : $url ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | sub _get_url_worker | ||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||
| 57 | 410 | ▶ | my $base = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_get_url_worker: called CC=21 SCAR=30.4
| |||||||||||||||||||||||||||||||||
| 58 | 410 | my $to = shift; | |||||||||||||||||||||||||||||||
| 59 | 410 | my $slash_terminated = shift; | |||||||||||||||||||||||||||||||
| 60 | 410 | my $no_leading_dot = shift; | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 410 | ▶ | my $prefix = ( $no_leading_dot ? "" : "./" ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 410 | my @this_url = @{ $base->_get_url() }; | |||||||||||||||||||||||||||||||
| 65 | 410 | my @other_url = @{ $to->_get_url() }; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 410 | my $ret; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 410 | my @this_url_bak = @this_url; | |||||||||||||||||||||||||||||||
| 70 | 410 | my @other_url_bak = @other_url; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 410 | ▶ | while (scalar(@this_url) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
scalar @this_url and scalar @other_url and $this_url[0] eq $other_url[0]
scalar @this_url and scalar @other_url
MC/DC100%2/2
scalar @this_url and scalar @other_url and $this_url[0] eq $other_url[0]
scalar @this_url
$this_url[0] eq $other_url[0]
Truth table100%3/3
A and B
A= scalar @this_urlB= $this_url[0] eq $other_url[0]
| |||||||||||||||||||||||||||||||||
| 73 | && scalar(@other_url) | ||||||||||||||||||||||||||||||||
| 74 | && ( $this_url[0] eq $other_url[0] ) ) | ||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||
| 76 | 139 | shift(@this_url); | |||||||||||||||||||||||||||||||
| 77 | 139 | shift(@other_url); | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 410 | ▶ | if ( ( !@this_url ) && ( !@other_url ) ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@this_url or @other_url
MC/DC100%2/2
@this_url or @other_url
@this_url
@other_url
Truth table100%3/3
A or B
A= @this_urlB= @other_url
| |||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||
| 82 | 38 | ▶ | if ( ( !$base->_is_dir() ) ne ( !$to->_is_dir() ) ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||
| 84 | 1 | die "Two identical URLs with non-matching _is_dir()'s"; | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | 37 | ▶ | if ( !$base->_is_dir() ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||
| 88 | 4 | ▶ | if ( scalar(@this_url_bak) ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||
| 90 | 3 | return $prefix . $this_url_bak[-1]; | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | else | ||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||
| 94 | 1 | die "Root URL is not a directory"; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 405 | ▶ | if ( ( $base->_mode() eq "harddisk" ) && ( $to->_is_dir() ) ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$base->_mode eq "harddisk" and $to->_is_dir
MC/DC100%2/2
$base->_mode eq "harddisk" and $to->_is_dir
$base->_mode eq "harddisk"
$to->_is_dir
Truth table100%3/3
A and B
A= $base->_mode eq "harddisk"B= $to->_is_dir
| |||||||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||||||
| 101 | 2 | push @other_url, "index.html"; | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 405 | $ret = ""; | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 405 | ▶ | if ($slash_terminated) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||
| 108 | 308 | ▶ | if ( ( scalar(@this_url) == 0 ) && ( scalar(@other_url) == 0 ) ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @this_url == 0 and scalar @other_url == 0
MC/DC100%2/2
scalar @this_url == 0 and scalar @other_url == 0
scalar @this_url == 0
scalar @other_url == 0
Truth table100%3/3
A and B
A= scalar @this_url == 0B= scalar @other_url == 0
| |||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||
| 110 | 29 | $ret = $prefix; | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | else | ||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||
| 114 | 279 | ▶ | if ( !$base->_is_dir() ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||||||
| 116 | 1 | pop(@this_url); | |||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | 279 | $ret .= join( "/", ( map { ".." } @this_url ), @other_url ); | |||||||||||||||||||||||||||||||
| 119 | 279 | ▶ | if ( $to->_is_dir() && ( $base->_mode() ne "harddisk" ) ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$to->_is_dir and $base->_mode ne "harddisk"
MC/DC100%2/2
$to->_is_dir and $base->_mode ne "harddisk"
$to->_is_dir
$base->_mode ne "harddisk"
Truth table100%3/3
A and B
A= $to->_is_dirB= $base->_mode ne "harddisk"
| |||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||
| 121 | 266 | $ret .= "/"; | |||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | else | ||||||||||||||||||||||||||||||||
| 126 | { | ||||||||||||||||||||||||||||||||
| 127 | my @components = | ||||||||||||||||||||||||||||||||
| 128 | 97 | ( ( map { ".." } @this_url[ 1 .. $#this_url ] ), @other_url ); | |||||||||||||||||||||||||||||||
| 129 | 97 | $ret .= ( $prefix . join( "/", @components ) ); | |||||||||||||||||||||||||||||||
| 130 | 97 | ▶ | if ( ( $to->_is_dir() ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
$to->_is_dir and $base->_mode ne "harddisk" and scalar @components
$to->_is_dir and $base->_mode ne "harddisk"
MC/DC100%2/2
$to->_is_dir and $base->_mode ne "harddisk" and scalar @components
$to->_is_dir
$base->_mode ne "harddisk"
Truth table100%3/3
A and B
A= $to->_is_dirB= $base->_mode ne "harddisk"
| |||||||||||||||||||||||||||||||||
| 131 | && ( $base->_mode() ne "harddisk" ) | ||||||||||||||||||||||||||||||||
| 132 | && scalar(@components) ) | ||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||
| 134 | 72 | $ret .= "/"; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | #if (($to->_is_dir()) && (scalar(@other_url) || $slash_terminated)) | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 405 | return $ret; | |||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 16 | 1; | |||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||||||