File Coverage

blib/lib/Kelp/Routes/Location.pm
Criterion Covered Total %
statement 12 12 100.0
branch 2 4 50.0
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 17 20 85.0


line stmt bran cond sub pod time code
1             package Kelp::Routes::Location;
2              
3 41     41   274 use Kelp::Base;
  41         78  
  41         288  
4 41     41   309 use Carp;
  41         103  
  41         12862  
5              
6             attr 'router' => sub { croak 'router is required' };
7             attr 'parent' => sub { croak 'parent is required' };
8              
9             sub add
10             {
11 6     6 0 55 my ($self, $pattern, $descr, $parent_data) = @_;
12 6         19 my $parent = $self->parent;
13              
14 6 50       15 croak "Cannot chain 'add' calls because the parent route was not parsed correctly"
15             unless $parent;
16              
17             # discard $parent_data from args
18 6 50       17 $parent_data = {
19             ($parent->has_name ? (name => $parent->name) : ()),
20             pattern => $parent->pattern,
21             };
22              
23             # parent is a bridge now (even if the add call fails)
24 6         20 $parent->bridge(1);
25 6         16 return $self->router->add($pattern, $descr, $parent_data);
26             }
27              
28             1;
29              
30             # internal only
31             # It's not a router reimplementation! It's just a facade for the add method of
32             # the router. Developers will interact with it without even knowing.
33