blib/lib/HTML/Breadcrumbs.pm

filter: Statementstmt 96.7% 178 / 184 Branchbran 90.6% 87 / 96 Conditioncond 77.3% 41 / 53 MC/DCmcdc 62.8% 22 / 35 Subroutinesub 100% 20 / 20 Podpod 0.0% 0 / 4 totaltotal 88.7% 348 / 392 CC 73 SCAR 20.9
CC
73
Cov
92%
_label
13.0
_setup_omit
13.0
_format
9.9
CRAP 8.1
↑ Summary
1 package HTML::Breadcrumbs;
2  
3 7 ▶use 5.000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 require Exporter;
8  
9 7 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 $VERSION = '0.7';
11 7 @ISA = qw(Exporter);
12 7 @EXPORT = ();
13 7 @EXPORT_OK = qw(breadcrumbs);
14  
15 7 my @ARG = qw(path roots indexes omit omit_regex map labels sep format format_last extra);
16  
17 #
18 # Initialise
19 #
20 sub _init
21 85 ▶{
Subroutine _init: called CC=4 SCAR=14.1
22 85 my $self = shift;
23 # Argument defaults
24 my %arg = (
25 path => $ENV{SCRIPT_NAME},
26 85 roots => [ '/' ],
27 indexes => [ 'index.html' ],
28 sep => ' > ',
29 format => '<a href="%s">%s</a>',
30 format_last => '%s',
31 @_,
32 );
33  
34 # Check for invalid args
35 85 my %ARG = map { $_ => 1 } @ARG;
36 85 my @bad = grep { ! exists $ARG{$_} } keys %arg;
37 85 ▶ croak "[Breadcrumbs::_init] invalid argument(s): " . join(',',@bad) if @bad;
Branch: 1 branch
BranchTrueFalseTotal
if @bad 2 83 85
38 croak "[Breadcrumbs::_init] 'path' argument must be absolute"
39 83 ▶ if $self->{path} && substr($self->{path},0,1) ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"path"} and substr($self->{"path"}, 0, 1) ne "/" 0 83 83
Condition33%1/3
$self->{"path"} and substr($self->{"path"}, 0, 1) ne "/"
!ll&&!rl&&r
8300
MC/DC0%0/2
$self->{"path"} and substr($self->{"path"}, 0, 1) ne "/"
$self->{"path"} substr($self->{"path"}, 0, 1) ne "/"
Truth table33%1/3
A and B
A= $self->{"path"}B= substr($self->{"path"}, 0, 1) ne "/"
ABresult
0X0
100
111
40  
41 # Add arguments to $self
42 83 @$self{ @ARG } = @arg{ @ARG };
43  
44 83 return $self;
45 }
46  
47 sub new
48 85 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
49 85 my $class = shift;
50 85 my $self = {};
51 85 bless $self, $class;
52 85 return $self->_init(@_);
53 }
54  
55 # Identify the root element
56 sub _setup_root
57 77 ▶{
Subroutine _setup_root: called CC=6 SCAR=17.9
58 77 my $self = shift;
59  
60 77 ▶ $self->{roots} = [ $self->{roots} ] if $self->{roots} && ! ref $self->{roots};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"roots"} and not ref $self->{"roots"} 1 76 77
Condition66%2/3
$self->{"roots"} and not ref $self->{"roots"}
!ll&&!rl&&r
0761
MC/DC50%1/2
$self->{"roots"} and not ref $self->{"roots"}
$self->{"roots"} not ref $self->{"roots"}
Truth table66%2/3
A and not(B)
A= $self->{"roots"}B= not ref $self->{"roots"}
ABresult
0X0
100
111
61 77 my $root = '/';
62 77 for my $r (sort { length($b) <=> length($a) } @{$self->{roots}}) {
63 77 ▶ if ($self->{path} =~ m/^$r\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"path"} =~ /^$r\b/) 74 3 77
64 74 $root = $r;
65 74 ▶ $root .= '/' if substr($root,-1) ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($root, -1) ne "/" 3 71 74
66 74 last;
67 }
68 }
69 77 push @{$self->{elt}}, $root;
70 77 $self->{root} = $root;
71 }
72  
73 # Setup omit stuff (omit hash, omit_regex arrayrefs)
74 sub _setup_omit
75 77 ▶{
Subroutine _setup_omit: called CC=13 SCAR=25.7
76 77 my $self = shift;
77  
78 77 $self->{omit_elt} = {};
79 77 $self->{omit_regex_elt} = [];
80 77 $self->{omit_regex_path} = [];
81  
82 $self->{omit} = [ $self->{omit} ]
83 77 ▶ if $self->{omit} && ! ref $self->{omit};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"omit"} and not ref $self->{"omit"} 6 71 77
Condition100%3/3
$self->{"omit"} and not ref $self->{"omit"}
!ll&&!rl&&r
6836
MC/DC100%2/2
$self->{"omit"} and not ref $self->{"omit"}
$self->{"omit"} not ref $self->{"omit"}
Truth table100%3/3
A and not(B)
A= $self->{"omit"}B= not ref $self->{"omit"}
ABresult
0X0
100
111
84 # Create a hash from omit elements
85 77 ▶ if ($self->{omit} && ref $self->{omit} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"omit"} and ref $self->{"omit"} eq "ARRAY") 9 68 77
Condition66%2/3
$self->{"omit"} and ref $self->{"omit"} eq "ARRAY"
!ll&&!rl&&r
6809
MC/DC50%1/2
$self->{"omit"} and ref $self->{"omit"} eq "ARRAY"
$self->{"omit"} ref $self->{"omit"} eq "ARRAY"
Truth table66%2/3
A and B
A= $self->{"omit"}B= ref $self->{"omit"} eq "ARRAY"
ABresult
0X0
100
111
86 9 for (@{$self->{omit}}) {
87 # Omit elements should be either absolute paths or element basenames
88 11 ▶ if (substr($_,0,1) eq '/') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($_, 0, 1) eq '/') { } 5 6 11
elsif (m[/]) { } 1 5 6
89 # Remove any trailing '/'
90 5 ▶ $_ = substr($_, 0, -1) if substr($_,-1) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, -1) eq "/" 1 4 5
91 } elsif (m!/!) {
92 1 warn "omit arguments must be either absolute paths or simple path basenames - skipping $_";
93 0 next;
94 }
95 10 $self->{omit_elt}->{$_} = 1;
96 }
97 }
98 76 ▶ my $omit_regex = $self->{omit_regex} || [];
Condition100%2/2
$self->{'omit_regex'} || []
l!l
1858
MC/DC100%1/1
$self->{'omit_regex'} || []
$self->{'omit_regex'}
Truth table100%2/2
A
A= $self->{'omit_regex'}
Aresult
11
00
99 76 ▶ $omit_regex = [ $omit_regex ] unless ref $omit_regex eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $omit_regex eq "ARRAY" 11 65 76
100 # Create seperate full-path and element omit_regex arrays
101 76 for my $o (@$omit_regex) {
102 18 ▶ if ($o =~ m!/!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o =~ m[/]) { } 7 11 18
103 7 $o =~ s!^\^!!;
104 7 $o =~ s!/*(\$)?$!!; #!
105 7 push @{$self->{omit_regex_path}}, qq(^$o\$);
106 }
107 else {
108 11 push @{$self->{omit_regex_elt}}, $o;
109 }
110 }
111 }
112  
113 # Add path elements to elt array
114 sub _add_elements
115 76 ▶{
Subroutine _add_elements: called CC=7 SCAR=19.5
116 76 my $self = shift;
117 76 my $current = $self->{root};
118 76 ▶ while ($self->{path} =~ m|^\Q$current\E/*(([^/]+)/?)|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"path"} =~ m[^\Q$current\E/*(([^/]+)/?)]) 215 76 291
119 215 my $final = $2;
120 215 $current .= $1;
121 # Remove any trailing '/' from current for testing
122 215 my $current_test = $current;
123 215 ▶ $current_test = substr($current_test, 0, -1) if substr($current_test, -1) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($current_test, -1) eq "/" 145 70 215
124 # Ignore elements explicitly omitted
125 215 ▶ next if $self->{omit_elt}->{$current_test} || $self->{omit_elt}->{$final};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"omit_elt"}{$current_test} or $self->{"omit_elt"}{$final} 10 205 215
Condition100%3/3
$self->{"omit_elt"}{$current_test} or $self->{"omit_elt"}{$final}
l!l&&r!l&&!r
55205
MC/DC100%2/2
$self->{"omit_elt"}{$current_test} or $self->{"omit_elt"}{$final}
$self->{"omit_elt"}{$current_test} $self->{"omit_elt"}{$final}
Truth table100%3/3
A or B
A= $self->{"omit_elt"}{$current_test}B= $self->{"omit_elt"}{$final}
ABresult
1X1
011
000
126 # Ignore elements matching omit_regex_elt patterns
127 205 ▶ next if grep { $final =~ m/$_/ } @{$self->{omit_regex_elt}};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$final =~ /$_/;} @{$$self{"omit_regex_elt"};} 8 197 205
128 # Ignore paths matching omit_regex_path patterns
129 197 ▶ next if grep { $current_test =~ m/$_/ } @{$self->{omit_regex_path}};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$current_test =~ /$_/;} @{$$self{"omit_regex_path"};} 3 194 197
130 # Otherwise add to elt array
131 194 push @{$self->{elt}}, $current;
132 }
133 }
134  
135 # Apply element mappings
136 sub _map_elements
137 2 ▶{
Subroutine _map_elements: called CC=9 SCAR=22.2
138 2 my $self = shift;
139 2 ▶ die "invalid map argument" if ref $self->{map} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"map"} ne "HASH" 0 2 2
140  
141 2 $self->{elt_map} = {};
142 ELT:
143 2 for my $elt (@{$self->{elt}}) {
144 8 for my $key (sort keys %{$self->{map}}) {
145 # Map elements must be either absolute paths or element basenames
146 13 my $key2 = $key;
147 13 ▶ if (substr($key2,0,1) eq '/') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($key2, 0, 1) eq '/') { } 11 2 13
elsif ($key2 =~ m[/]) { } 0 2 2
148 # Absolute paths must end in '/'
149 11 ▶ $key2 .= '/' unless substr($key2,-1) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($key2, -1) eq "/" 3 8 11
150 } elsif ($key2 =~ m!/!) {
151 0 warn "map arguments must be either absolute paths or simple path basenames - skipping $key2";
152 0 next;
153 }
154  
155 # If the map key matches this element, record map value in elt_map
156 13 ▶ my $match = ($key2 =~ m!/!) ? $elt eq $key2 : $elt =~ m,/\Q$key2\E/$,;
Branch: 1 branch
BranchTrueFalseTotal
$key2 =~ m[/] ? : 11 2 13
157 13 ▶ if ($match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match) 4 9 13
158 4 $self->{elt_map}->{$elt} = $self->{map}->{$key};
159 4 next ELT;
160 }
161 }
162 }
163 }
164  
165 # Check the final element for indexes
166 sub _check_final_index_element
167 76 ▶{
Subroutine _check_final_index_element: called CC=5 SCAR=16.1
168 76 my $self = shift;
169  
170 $self->{indexes} = [ $self->{indexes} ]
171 76 ▶ if $self->{indexes} && ! ref $self->{indexes};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"indexes"} and not ref $self->{"indexes"} 1 75 76
Condition66%2/3
$self->{"indexes"} and not ref $self->{"indexes"}
!ll&&!rl&&r
0751
MC/DC50%1/2
$self->{"indexes"} and not ref $self->{"indexes"}
$self->{"indexes"} not ref $self->{"indexes"}
Truth table66%2/3
A and not(B)
A= $self->{"indexes"}B= not ref $self->{"indexes"}
ABresult
0X0
100
111
172 76 ▶ if (ref $self->{indexes} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"indexes"} eq "ARRAY") 76 0 76
173 # Convert indexes to hash
174 76 my %indexes = map { $_ => 1 } @{$self->{indexes}};
175 # Check final element
176 76 my $final = basename($self->{elt}->[ $#{$self->{elt}} ]);
177 76 ▶ if ($indexes{$final}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indexes{$final}) 4 72 76
178 4 pop @{$self->{elt}};
179 }
180 }
181 }
182  
183 #
184 # Split the path into elements (stored in $self->{elt} arrayref)
185 #
186 sub _split
187 77 ▶{
Subroutine _split: called CC=2 SCAR=6.9
188 77 my $self = shift;
189 77 $self->{elt} = [];
190  
191 # Identify the root
192 77 $self->_setup_root;
193  
194 # Setup omit stuff
195 77 $self->_setup_omit;
196  
197 # Add path elements to elt array
198 76 $self->_add_elements;
199  
200 # Apply element mappings
201 76 ▶ $self->_map_elements if $self->{'map'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"map"} 2 74 76
202  
203 # Check for final index elements
204 76 $self->_check_final_index_element;
205  
206 }
207  
208 #
209 # Generate a default label for $elt
210 #
211 sub _label_default
212 250 ▶{
Subroutine _label_default: called CC=7 SCAR=19.5
213 250 my $self = shift;
214 250 my ($elt, $last, $extra) = @_;
215 250 my $label = '';
216  
217 250 ▶ if ($elt eq '/' || $elt eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt eq '/' or $elt eq '') { } 71 179 250
Condition66%2/3
$elt eq "/" or $elt eq ""
l!l&&r!l&&!r
710179
MC/DC50%1/2
$elt eq "/" or $elt eq ""
$elt eq "/" $elt eq ""
Truth table66%2/3
A or B
A= $elt eq "/"B= $elt eq ""
ABresult
1X1
011
000
218 71 $label = 'Home';
219 }
220 else {
221 179 ▶ $elt = substr($elt,0,-1) if substr($elt,-1) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($elt, -1) eq "/" 108 71 179
222 179 $label = basename($elt);
223 179 ▶ $label =~ s/\.[^.]*$// if $last;
Branch: 1 branch
BranchTrueFalseTotal
if $last 70 109 179
224 179 ▶ $label = ucfirst($label) if lc($label) eq $label && $label =~ m/^\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
if lc $label eq $label and $label =~ /^\w+$/ 170 9 179
Condition100%3/3
lc $label eq $label and $label =~ /^\w+$/
!ll&&!rl&&r
63170
MC/DC100%2/2
lc $label eq $label and $label =~ /^\w+$/
lc $label eq $label $label =~ /^\w+$/
Truth table100%3/3
A and B
A= lc $label eq $labelB= $label =~ /^\w+$/
ABresult
0X0
100
111
225 }
226  
227 250 return $label;
228 }
229  
230 #
231 # Return a label for the given element
232 #
233 sub _label
234 266 ▶{
Subroutine _label: called CC=13 SCAR=25.7
235 266 my $self = shift;
236 266 my ($elt, $last, $extra) = @_;
237 266 my $label = '';
238  
239 # Check $self->{labels}
240 266 ▶ if (ref $self->{labels} eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'labels'} eq 'CODE') { } 12 254 266
elsif (ref $self->{'labels'} eq 'HASH') { } 40 214 254
241 12 ▶ $elt = substr($elt,0,-1) if substr($elt,-1) eq '/' && $elt ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($elt, -1) eq "/" and $elt ne "/" 6 6 12
Condition100%3/3
substr($elt, -1) eq "/" and $elt ne "/"
!ll&&!rl&&r
336
MC/DC100%2/2
substr($elt, -1) eq "/" and $elt ne "/"
substr($elt, -1) eq "/" $elt ne "/"
Truth table100%3/3
A and B
A= substr($elt, -1) eq "/"B= $elt ne "/"
ABresult
0X0
100
111
242 12 $label = $self->{labels}->($elt, basename($elt), $last, $extra);
243 }
244 elsif (ref $self->{labels} eq 'HASH') {
245 40 ▶ $elt = substr($elt,0,-1) if substr($elt,-1) eq '/' && $elt ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($elt, -1) eq "/" and $elt ne "/" 20 20 40
Condition100%3/3
substr($elt, -1) eq "/" and $elt ne "/"
!ll&&!rl&&r
101020
MC/DC100%2/2
substr($elt, -1) eq "/" and $elt ne "/"
substr($elt, -1) eq "/" $elt ne "/"
Truth table100%3/3
A and B
A= substr($elt, -1) eq "/"B= $elt ne "/"
ABresult
0X0
100
111
246 40 ▶ $label ||= $self->{labels}->{$elt};
Condition66%2/3
$label ||= $self->{"labels"}{$elt}
l!l&&r!l&&!r
0337
MC/DC50%1/2
$label ||= $self->{"labels"}{$elt}
$label $self->{"labels"}{$elt}
Truth table66%2/3
A ||= B
A= $labelB= $self->{"labels"}{$elt}
ABresult
1X1
011
000
247 40 ▶ $label ||= $self->{labels}->{$elt . '/'} unless $elt eq '/' || $last;
Branch: 1 branch
BranchTrueFalseTotal
unless $elt eq "/" or $last 20 20 40
Condition100%6/6
$elt eq "/" or $last
l!l&&r!l&&!r
101020
$label ||= $self->{"labels"}{$elt . '/'}
l!l&&r!l&&!r
2216
MC/DC100%2/2
$elt eq "/" or $last
$elt eq "/" $last
MC/DC100%2/2
$label ||= $self->{"labels"}{$elt . '/'}
$label $self->{"labels"}{$elt . '/'}
Truth table100%3/3
A or B
A= $elt eq "/"B= $last
ABresult
1X1
011
000
Truth table100%3/3
A ||= B
A= $labelB= $self->{"labels"}{$elt . '/'}
ABresult
1X1
011
000
248 40 ▶ $label ||= $self->{labels}->{basename($elt)};
Condition100%3/3
$label ||= $self->{"labels"}{basename($elt)}
l!l&&r!l&&!r
5332
MC/DC100%2/2
$label ||= $self->{"labels"}{basename($elt)}
$label $self->{"labels"}{basename($elt)}
Truth table100%3/3
A ||= B
A= $labelB= $self->{"labels"}{basename($elt)}
ABresult
1X1
011
000
249 }
250  
251 # Else use defaults
252 266 ▶ $label ||= $self->_label_default($elt, $last, $extra);
Condition66%2/3
$label ||= $self->_label_default($elt, $last, $extra)
l!l&&r!l&&!r
162500
MC/DC0%0/2
$label ||= $self->_label_default($elt, $last, $extra)
$label $self->_label_default($elt, $last, $extra)
Truth table66%2/3
A ||= B
A= $labelB= $self->_label_default($elt, $last, $extra)
ABresult
1X1
011
000
253  
254 266 return $label;
255 }
256  
257 #
258 # Render the elt path for URI use, and lookup in elt_map if applicable
259 #
260 sub _uri_elt
261 190 ▶{
Subroutine _uri_elt: called CC=2 SCAR=6.9
262 190 my $self = shift;
263 190 local $_ = shift;
264 190 ▶ $_ = $self->{elt_map}->{$_} if exists $self->{elt_map}->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"elt_map"}{$_} 4 186 190
265 # URI escape - should maybe use URI::Escape here instead
266 190 s/ /%20/g;
267 190 return $_;
268 }
269  
270 #
271 # HTML-format the breadcrumbs
272 #
273 sub _format
274 76 ▶{
Subroutine _format: called CC=9 SCAR=22.9
275 76 my $self = shift;
276  
277 76 my $out;
278 76 ▶ for (my $i = 0; $i <= $#{$self->{elt}}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$$self{"elt"};}) 266 76 342
279  
280 # Format breadcrumb links
281 266 ▶ if ($i != $#{$self->{elt}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i != $#{$$self{'elt'};}) { } 190 76 266
282 # Generate label
283 190 my $label = $self->_label($self->{elt}->[$i], undef, $self->{extra});
284  
285 # $self->{format} coderef
286 190 ▶ if (ref $self->{format} eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'format'} eq 'CODE') { } 6 184 190
elsif ($self->{'format'} and not ref $self->{'format'}) { } 184 0 184
287 $out .= $self->{format}->($self->_uri_elt($self->{elt}->[$i]),
288 6 $label, $self->{extra});
289 }
290 # $self->{format} sprintf pattern
291 ▶ elsif ($self->{format} && ! ref $self->{format}) {
Condition33%1/3
$self->{"format"} and not ref $self->{"format"}
!ll&&!rl&&r
00184
MC/DC0%0/2
$self->{"format"} and not ref $self->{"format"}
$self->{"format"} not ref $self->{"format"}
Truth table33%1/3
A and not(B)
A= $self->{"format"}B= not ref $self->{"format"}
ABresult
0X0
100
111
292 184 $out .= sprintf $self->{format}, $self->_uri_elt($self->{elt}->[$i]),
293 $label;
294 }
295 # Else croak
296 else {
297 0 croak "[Breadcrumbs::format] invalid format $self->{format}";
298 }
299  
300 # Separator
301 190 $out .= $self->{sep};
302 }
303  
304 # Format final element breadcrumb label
305 else {
306 # Generate label
307 76 my $label = $self->_label($self->{elt}->[$i], 'last', $self->{extra});
308  
309 # $self->{format_last} coderef
310 76 ▶ if (ref $self->{format_last} eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'format_last'} eq 'CODE') { } 2 74 76
elsif ($self->{'format_last'} and not ref $self->{'format_last'}) { } 74 0 74
311 2 $out .= $self->{format_last}->($label, $self->{extra});
312 }
313 # $self->{format_last} sprintf pattern
314 ▶ elsif ($self->{format_last} && ! ref $self->{format_last}) {
Condition33%1/3
$self->{"format_last"} and not ref $self->{"format_last"}
!ll&&!rl&&r
0074
MC/DC0%0/2
$self->{"format_last"} and not ref $self->{"format_last"}
$self->{"format_last"} not ref $self->{"format_last"}
Truth table33%1/3
A and not(B)
A= $self->{"format_last"}B= not ref $self->{"format_last"}
ABresult
0X0
100
111
315 74 $out .= sprintf $self->{format_last}, $label;
316 }
317 # Else croak
318 else {
319 0 croak "[Breadcrumbs::format] invalid format_last $self->{format_last}";
320 }
321 }
322 }
323  
324 76 return $out;
325 }
326  
327 #
328 # The real work - process and render the given path
329 #
330 sub render
331 83 ▶{
Subroutine render: called CC=6 SCAR=18.1
Pod undocumented
332 83 my $self = shift;
333 83 my %arg = @_;
334  
335 # Check for invalid args
336 83 my %ARG = map { $_ => 1 } @ARG;
337 0 my @bad = grep { ! exists $ARG{$_} } keys %arg;
338 83 ▶ croak "[Breadcrumbs::render] invalid argument(s): " . join(',',@bad) if @bad;
Branch: 1 branch
BranchTrueFalseTotal
if @bad 0 83 83
339  
340 # Add args to $self
341 83 for (@ARG) {
342 913 ▶ $self->{$_} = $arg{$_} if defined $arg{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg{$_} 0 913 913
343 }
344  
345 # Croak if no path
346 83 ▶ croak "[Breadcrumbs::render] no valid 'path' found" if ! $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"path"} 3 80 83
347 croak "[Breadcrumbs::render] 'path' argument must be absolute"
348 80 ▶ if substr($self->{path},0,1) ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($self->{"path"}, 0, 1) ne "/" 3 77 80
349  
350 # Split the path into elements
351 77 $self->_split();
352  
353 # Format
354 76 return $self->_format();
355 }
356  
357 #
358 # Alias for render
359 #
360 sub to_string
361 2 ▶{
Subroutine to_string: called CC=1 SCAR=0.0
Pod undocumented
362 2 my $self = shift;
363 2 $self->render(@_);
364 }
365  
366 #
367 # Procedural interface
368 #
369 sub breadcrumbs
370 73 ▶{
Subroutine breadcrumbs: called CC=2 SCAR=7.1
Pod undocumented
371 73 my $bc = HTML::Breadcrumbs->new(@_);
372 72 ▶ croak "[breadcrumbs] object creation failed!" if ! ref $bc;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $bc 0 72 72
373 72 return $bc->render();
374 }
375  
376 7 1;
377  
378 __END__
↑ Summary