blib/lib/Mojolicious/Plugin/Breadcrumbs.pm

filter: Statementstmt 100% 25 / 25 Branchbran 100% 6 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 92.6% 38 / 41 CC 6 SCAR 14.7
CC
6
Cov
97%
__ANON__
6.0
register
1.0
BEGIN
1.0
CRAP 4.3
↑ Summary
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
BranchTrueFalseTotal
@_ and $Crumbs_Map = shift() 1 4 5
20  
21 5 ▶ length $c->url_for->to_string
Branch: 1 branch
BranchTrueFalseTotal
length $c->url_for->to_string or return 4 1 5
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
BranchTrueFalseTotal
$path eq '/' ? : 2 6 8
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 }
l!l&&r!l&&!r
620
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 }
ABresult
1X1
011
000
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__
↑ Summary