| 1 | package Mojolicious::Plugin::Breadcrumbs; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 4 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 4 | our $VERSION = '1.001003'; # VERSION | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 4 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 4 | my $Crumbs_Map = { | |||||||||||||||||||
| 10 | '/' => 'Home', | ||||||||||||||||||||
| 11 | }; | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | ▶ | sub register { | ||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 14 | 2 | my ($self, $app) = @_; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | $app->helper( | ||||||||||||||||||||
| 17 | 5 | ▶ | breadcrumbs => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||
| 18 | 5 | my $c = shift; | |||||||||||||||||||
| 19 | 5 | ▶ | @_ and $Crumbs_Map = shift; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 5 | ▶ | length $c->url_for->to_string | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | or return; # if this is the case, we're just setting the | ||||||||||||||||||||
| 23 | # $Crumbs_Map and not needing crumbs; | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 4 | my $path = ''; | |||||||||||||||||||
| 26 | 4 | my @crumbs; | |||||||||||||||||||
| 27 | 4 | for my $crumb ( | |||||||||||||||||||
| 28 | '', grep length, split m{/}, $c->url_for->to_string | ||||||||||||||||||||
| 29 | ) { | ||||||||||||||||||||
| 30 | 8 | ▶ | $path .= ($path eq '/' ? '' : '/') . $crumb; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | push @crumbs, { | ||||||||||||||||||||
| 32 | path => $path, | ||||||||||||||||||||
| 33 | text => $Crumbs_Map->{ $path } | ||||||||||||||||||||
| 34 | 8 | ▶ | // do{ | ||||||||||||||||||
|
Condition66%2/3
$Crumbs_Map->{$path} // do {
(my $x = $crumb) =~ tr/\-_/ /;
ucfirst $x
}
MC/DC0%0/2
$Crumbs_Map->{$path} // do {
(my $x = $crumb) =~ tr/\-_/ /;
ucfirst $x
}
$Crumbs_Map->{$path}
do {
(my $x = $crumb) =~ tr/\-_/ /;
ucfirst $x
}
Truth table66%2/3
A // B
A= $Crumbs_Map->{$path}B= do {
(my $x = $crumb) =~ tr/\-_/ /;
ucfirst $x
}
| |||||||||||||||||||||
| 35 | 2 | ( my $x = $crumb ) =~ tr/-_/ /; | |||||||||||||||||||
| 36 | 2 | ucfirst $x; | |||||||||||||||||||
| 37 | }, | ||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 4 | my $current_page = pop @crumbs; | |||||||||||||||||||
| 42 | 4 | my $bread = '<section class="breadcrumbs">' . | |||||||||||||||||||
| 43 | join(q{<span class="breadcrumb_sep">▸</span>}, | ||||||||||||||||||||
| 44 | (map qq{<a href="$_->{path}">$_->{text}</a>}, @crumbs), | ||||||||||||||||||||
| 45 | '', | ||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | $bread .= '<span class="last_breadcrumb">' | ||||||||||||||||||||
| 49 | 4 | . ($current_page->{text}) . '</span></section>'; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 4 | return $bread; | |||||||||||||||||||
| 52 | }, | ||||||||||||||||||||
| 53 | 2 | ); | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 4 | ' | |||||||||||||||||||
| 57 | Q. Why was the statement scared while the comment was not? | ||||||||||||||||||||
| 58 | A. Statements are executed. | ||||||||||||||||||||
| 59 | '; | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||