| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | Mojolicious::Plugin::Toto - A simple tab and object based site structure | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | use Mojolicious::Lite; | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | plugin 'toto' => | ||||||||||||||||||||||||||||
| 12 | nav => [ qw{brewery pub beer} ], | ||||||||||||||||||||||||||||
| 13 | sidebar => { | ||||||||||||||||||||||||||||
| 14 | brewery => [ qw{brewery/list brewery/search brewery} ], | ||||||||||||||||||||||||||||
| 15 | pub => [ qw{pub/list pub/search pub} ], | ||||||||||||||||||||||||||||
| 16 | beer => [ qw{beer/list beer/search beer} ], | ||||||||||||||||||||||||||||
| 17 | }, | ||||||||||||||||||||||||||||
| 18 | tabs => { | ||||||||||||||||||||||||||||
| 19 | brewery => [qw/view edit delete/], | ||||||||||||||||||||||||||||
| 20 | pub => [qw/view edit delete/], | ||||||||||||||||||||||||||||
| 21 | beer => [qw/view edit delete/], | ||||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | app->start; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | This plugin provides a navigational structure and a default set | ||||||||||||||||||||||||||||
| 29 | of routes for a Mojolicious or Mojolicious::Lite app | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | The navigational structure is a slight variation of | ||||||||||||||||||||||||||||
| 32 | L<this|http://twitter.github.com/bootstrap/examples/fluid.html> | ||||||||||||||||||||||||||||
| 33 | example used by twitter's L<bootstrap|http://twitter.github.com/bootstrap>. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | The plugin provides a sidebar, a nav bar, and also a | ||||||||||||||||||||||||||||
| 36 | row of tabs underneath the name of an object. | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | The row of tabs is an extension of BREAD or CRUD -- in a BREAD | ||||||||||||||||||||||||||||
| 39 | application, browse and add are operations on zero or many objects, | ||||||||||||||||||||||||||||
| 40 | while edit, add, and delete are operations on one object. In | ||||||||||||||||||||||||||||
| 41 | the toto structure, these two types of operations are distinguished | ||||||||||||||||||||||||||||
| 42 | by placing the former in the side nav bar, and the latter in | ||||||||||||||||||||||||||||
| 43 | a row of tabs underneath the object to which the action applies. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Additionally, a top nav bar contains menu items to take the user | ||||||||||||||||||||||||||||
| 46 | to a particular side bar. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head1 HOW DOES IT WORK | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | After loading the toto plugin, the default layout is set to 'toto'. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Defaults routes are generated for every sidebar entry and tab entry. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | The names of the routes are of the form "controller/action", where | ||||||||||||||||||||||||||||
| 55 | controller is both the controller class and the model class. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | The following templates will be automagically used, if found | ||||||||||||||||||||||||||||
| 58 | (in order of preference) : | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | - templates/<controller>/<instance>/<action>.html.ep | ||||||||||||||||||||||||||||
| 61 | - templates/<controller>/<action>.html.ep | ||||||||||||||||||||||||||||
| 62 | - templates/<action>.html.ep | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Or if no object is selected : | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | - templates/<controller>/none_selected.html.ep | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | (This one links connects to "list" and "search" if | ||||||||||||||||||||||||||||
| 69 | these routes exist, and provides an autocomplete | ||||||||||||||||||||||||||||
| 70 | form if the model class has an autocomplete() method.) | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Also the templates "single" and "plural" are built-in | ||||||||||||||||||||||||||||
| 73 | fallbacks for the two cases described above. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | The stash values "object" and "tab" are set for each auto-generated route. | ||||||||||||||||||||||||||||
| 76 | Also "noun" is set as an alias to "object". | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | A version of twitter's L<bootstrap|http://twitter.github.com/bootstrap> is | ||||||||||||||||||||||||||||
| 79 | included in this distribution. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | In addition to "menu", "nav/sidebar/tabs", the following options are recognized : | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =over | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =item prefix | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | prefix => /my/subpath | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | A prefix to prepend to the path for the toto routes. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =item head_route | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | head_route => $app->routes->find('top_route"); | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | A Mojolicious::Route::Route object to use as the parent for all routes. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =item model_namespace | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | model_namespace => "Myapp::Model' | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | A namespace for model classes : the model class will be camelized and appended to this. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =back | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 EXAMPLE | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | There are two different structures that toto will accept. | ||||||||||||||||||||||||||||
| 110 | One is intended for a simple CRUD structure, where each | ||||||||||||||||||||||||||||
| 111 | object has its own top level navigational item and | ||||||||||||||||||||||||||||
| 112 | a variety of possible actions. The other form is intended | ||||||||||||||||||||||||||||
| 113 | for a more complex situation in which the list of objects | ||||||||||||||||||||||||||||
| 114 | does not correspond to the list of choices in the navigation | ||||||||||||||||||||||||||||
| 115 | bar. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head2 Simple structure | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | The "menu" format can be used to automatically generate | ||||||||||||||||||||||||||||
| 120 | the nav bar, side bar and rows of tabs, using actions | ||||||||||||||||||||||||||||
| 121 | which correspond to many objects or actions which | ||||||||||||||||||||||||||||
| 122 | correspond to one object. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | use Mojolicious::Lite; | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | plugin 'toto' => | ||||||||||||||||||||||||||||
| 129 | menu => [ | ||||||||||||||||||||||||||||
| 130 | beer => { | ||||||||||||||||||||||||||||
| 131 | many => [qw/search browse/], | ||||||||||||||||||||||||||||
| 132 | one => [qw/picture ingredients pubs/], | ||||||||||||||||||||||||||||
| 133 | }, | ||||||||||||||||||||||||||||
| 134 | pub => { | ||||||||||||||||||||||||||||
| 135 | many => [qw/map list search/], | ||||||||||||||||||||||||||||
| 136 | one => [qw/info comments/], | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | ]; | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | app->start; | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head2 Complex structure | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | The "nav/sidebar/tabs" format can be used | ||||||||||||||||||||||||||||
| 145 | for a more versatile structure, in which the | ||||||||||||||||||||||||||||
| 146 | nav bar and side bar are less constrained. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | use Mojolicious::Lite; | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | get '/my/url/to/list/beers' => sub { | ||||||||||||||||||||||||||||
| 151 | shift->render_text("Here is a page for listing beers."); | ||||||||||||||||||||||||||||
| 152 | } => "beer/list"; | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | get '/beer/create' => sub { | ||||||||||||||||||||||||||||
| 155 | shift->render_text("Here is a page to create a beer."); | ||||||||||||||||||||||||||||
| 156 | } => "beer/create"; | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | plugin 'toto' => | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # top nav bar items | ||||||||||||||||||||||||||||
| 161 | nav => [ | ||||||||||||||||||||||||||||
| 162 | 'brewpub', # Refers to a sidebar entry below | ||||||||||||||||||||||||||||
| 163 | 'beverage' # Refers to a sidebar entry below | ||||||||||||||||||||||||||||
| 164 | ], | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # possible sidebars, keyed on nav entries | ||||||||||||||||||||||||||||
| 167 | sidebar => { | ||||||||||||||||||||||||||||
| 168 | brewpub => [ | ||||||||||||||||||||||||||||
| 169 | 'brewery/phonelist', | ||||||||||||||||||||||||||||
| 170 | 'brewery/mailing_list', | ||||||||||||||||||||||||||||
| 171 | 'pub/search', | ||||||||||||||||||||||||||||
| 172 | 'pub/map', | ||||||||||||||||||||||||||||
| 173 | 'brewery', # Refers to a "tab" entry below | ||||||||||||||||||||||||||||
| 174 | 'pub', # Refers to a "tab" entry below | ||||||||||||||||||||||||||||
| 175 | ], | ||||||||||||||||||||||||||||
| 176 | beverage => | ||||||||||||||||||||||||||||
| 177 | [ 'beer/list', # This will use the route defined above named "beer/list" | ||||||||||||||||||||||||||||
| 178 | 'beer/create', | ||||||||||||||||||||||||||||
| 179 | 'beer/search', | ||||||||||||||||||||||||||||
| 180 | 'beer/browse', # This will use the controller at the top (Beer::browse) | ||||||||||||||||||||||||||||
| 181 | 'beer' # Refers to a "tab" entry below | ||||||||||||||||||||||||||||
| 182 | ], | ||||||||||||||||||||||||||||
| 183 | }, | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # possible rows of tabs, keyed on sidebar entries without a / | ||||||||||||||||||||||||||||
| 186 | tabs => { | ||||||||||||||||||||||||||||
| 187 | brewery => [ 'view', 'edit', 'directions', 'beers', 'info' ], | ||||||||||||||||||||||||||||
| 188 | pub => [ 'view', 'info', 'comments', 'hours' ], | ||||||||||||||||||||||||||||
| 189 | beer => [ 'view', 'edit', 'pictures', 'notes' ], | ||||||||||||||||||||||||||||
| 190 | }; | ||||||||||||||||||||||||||||
| 191 | ; | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | app->start; | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =head1 NOTES | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | To create pages outside of the toto framework, just set the layout to | ||||||||||||||||||||||||||||
| 199 | something other than "toto', e.g. | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | get '/no/toto' => { layout => 'default' } => ... | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | This module is experimental. The API may change without notice. Feedback is welcome! | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =head1 TODO | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | Document the autcomplete API. | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | Brian Duggan C<bduggan@matatu.org> | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =cut | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | package Mojolicious::Plugin::Toto; | ||||||||||||||||||||||||||||
| 216 | 4 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 217 | 4 | ▶ | use Mojo::ByteStream qw/b/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 218 | 4 | ▶ | use File::Basename 'dirname'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 219 | 4 | ▶ | use File::Spec::Functions 'catdir'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 220 | 4 | ▶ | use Mojolicious::Plugin::Toto::Model; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 221 | 4 | ▶ | use Cwd qw/abs_path/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 224 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 4 | our $VERSION = "0.25"; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | sub _render_static { | ||||||||||||||||||||||||||
|
Subroutine
_render_static: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 229 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 230 | 0 | my $what = shift; | |||||||||||||||||||||||||||
| 231 | 0 | $c->render_static($what); | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 34 | ▶ | sub _cando { | ||||||||||||||||||||||||||
|
Subroutine
_cando: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 235 | 34 | my ($namespace,$controller,$action) = @_; | |||||||||||||||||||||||||||
| 236 | 34 | ▶ | my $package = join '::', ( $namespace || () ), b($controller)->camelize; | ||||||||||||||||||||||||||
|
Condition66%2/3
$namespace || ()
MC/DC0%0/2
$namespace || ()
$namespace
()
Truth table66%2/3
A || B
A= $namespaceB= ()
| |||||||||||||||||||||||||||||
| 237 | 34 | ▶ | return $package->can($action) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub _to_noun { | ||||||||||||||||||||||||||
|
Subroutine
_to_noun: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 241 | 0 | my $word = shift; | |||||||||||||||||||||||||||
| 242 | 0 | $word =~ s/_/ /g; | |||||||||||||||||||||||||||
| 243 | 0 | $word; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 14 | ▶ | sub _add_sidebar { | ||||||||||||||||||||||||||
|
Subroutine
_add_sidebar: called CC=13 SCAR=25.9
| |||||||||||||||||||||||||||||
| 247 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 248 | 14 | my $app = shift; | |||||||||||||||||||||||||||
| 249 | 14 | my $routes = shift; | |||||||||||||||||||||||||||
| 250 | 14 | my ($prefix, $nav_item, $object, $tab) = @_; | |||||||||||||||||||||||||||
| 251 | 14 | ▶ | die "no tab for $object" unless $tab; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 14 | ▶ | die "no nav item" unless $nav_item; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | my ($template) = ( | ||||||||||||||||||||||||||||
| 255 | 28 | ▶ | ( map { (-e "$_/$object/$tab.html.ep") ? "$object/$tab" : () } @{ $app->renderer->paths } ), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 14 | ▶ | ( map { (-e "$_/$tab.html.ep" ) ? "$tab" : () } @{ $app->renderer->paths } ), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | ); | ||||||||||||||||||||||||||||
| 258 | 14 | ▶ | $template = $tab if $app->renderer->get_data_template({template => $tab, format => 'html', handler => 'ep'}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 14 | ▶ | $template = "$object/$tab" if $app->renderer->get_data_template({template => "$object/$tab", format => "html", handler => "ep"}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 14 | ▶ | my $namespaces = $routes->can('namespaces') ? $routes->namespaces : $routes->root->namespaces; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 14 | ▶ | $namespaces = [ '' ] unless $namespaces && @$namespaces; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$namespaces and @$namespaces
MC/DC50%1/2
$namespaces and @$namespaces
$namespaces
@$namespaces
Truth table66%2/3
A and B
A= $namespacesB= @$namespaces
| |||||||||||||||||||||||||||||
| 263 | 14 | my $found_controller = grep { _cando($_,$object,$tab) } @$namespaces; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 14 | $app->log->debug("Adding sidebar route for $prefix/$object/$tab"); | |||||||||||||||||||||||||||
| 266 | 14 | ▶ | $app->log->debug("found template $template for $object/$tab ($nav_item)") if $template; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | my $r = $routes->under( | ||||||||||||||||||||||||||||
| 269 | 10 | ▶ | "$prefix/$object/$tab" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 270 | 10 | my $c = shift; | |||||||||||||||||||||||||||
| 271 | 10 | ▶ | $c->stash->{template} = $template || "plural"; | ||||||||||||||||||||||||||
|
Condition100%2/2
$template || 'plural'
MC/DC100%1/1
$template || 'plural'
$template
Truth table100%2/2
A
A= $template
| |||||||||||||||||||||||||||||
| 272 | 10 | $c->stash(object => $object); | |||||||||||||||||||||||||||
| 273 | 10 | $c->stash(noun => $object); | |||||||||||||||||||||||||||
| 274 | 10 | $c->stash(tab => $tab); | |||||||||||||||||||||||||||
| 275 | 10 | $c->stash(nav_item => $nav_item); | |||||||||||||||||||||||||||
| 276 | 14 | })->any; | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 14 | ▶ | $app->log->debug("found controller for $object/$tab (controller : $object, action : $tab)") if $found_controller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 14 | ▶ | $r = $r->to(controller => $object, action => $tab) if $found_controller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 14 | $r->name("$object/$tab"); | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 20 | ▶ | sub _add_tab { | ||||||||||||||||||||||||||
|
Subroutine
_add_tab: called CC=11 SCAR=33.7
| |||||||||||||||||||||||||||||
| 284 | 20 | my $self = shift; | |||||||||||||||||||||||||||
| 285 | 20 | my $app = shift; | |||||||||||||||||||||||||||
| 286 | 20 | my $routes = shift; | |||||||||||||||||||||||||||
| 287 | 20 | my ($prefix, $nav_item, $object, $tab) = @_; | |||||||||||||||||||||||||||
| 288 | my ($default_template) = ( | ||||||||||||||||||||||||||||
| 289 | 40 | ▶ | ( map { (-e "$_/$object/$tab.html.ep") ? "$object/$tab" : () } @{ $app->renderer->paths } ), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 20 | ▶ | ( map { (-e "$_/$tab.html.ep" ) ? "$tab" : () } @{ $app->renderer->paths } ), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | ); | ||||||||||||||||||||||||||||
| 292 | 20 | ▶ | $default_template = $tab if $app->renderer->get_data_template({template => $tab, format => "html", handler => "ep"}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 20 | ▶ | $default_template = "$object/$tab" if $app->renderer->get_data_template({template => "$object/$tab", format => "html", handler => "ep"}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 20 | ▶ | my $namespaces = $routes->can('namespaces') ? $routes->namespaces : $routes->root->namespaces; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 20 | ▶ | $namespaces = [ '' ] unless $namespaces && @$namespaces; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$namespaces and @$namespaces
MC/DC50%1/2
$namespaces and @$namespaces
$namespaces
@$namespaces
Truth table66%2/3
A and B
A= $namespacesB= @$namespaces
| |||||||||||||||||||||||||||||
| 297 | 20 | my $found_controller = grep { _cando($_,$object,$tab) } @$namespaces; | |||||||||||||||||||||||||||
| 298 | 20 | $app->log->debug("Adding route for $prefix/$object/$tab/*key"); | |||||||||||||||||||||||||||
| 299 | 20 | ▶ | $app->log->debug("Found controller class for $object/$tab/key") if $found_controller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 20 | ▶ | $app->log->debug("Found default template for $object/$tab/key ($default_template)") if $default_template; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | my $r = $routes->under("$prefix/$object/$tab/(*key)" | ||||||||||||||||||||||||||||
| 302 | => { key => '', show_tabs => 1 } | ||||||||||||||||||||||||||||
| 303 | 0 | ▶ | => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 304 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 305 | 0 | my $template = $default_template; | |||||||||||||||||||||||||||
| 306 | 0 | my $key = lc $c->stash('key'); | |||||||||||||||||||||||||||
| 307 | 0 | $c->stash(object => $object); | |||||||||||||||||||||||||||
| 308 | 0 | $c->stash(noun => _to_noun($object)); | |||||||||||||||||||||||||||
| 309 | 0 | $c->stash(tab => $tab); | |||||||||||||||||||||||||||
| 310 | 0 | ▶ | if ( $key ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if ( ( grep { -e "$_/$object/$key/$tab.html.ep" } @{ $app->renderer->paths } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
grep {-e "$_/$object/$key/$tab.html.ep";} @{$app->renderer->paths;} or $c->app->renderer->get_data_template({"template", "$object/$key/$tab", "format", "html", "handler", "ep"})
MC/DC0%0/2
grep {-e "$_/$object/$key/$tab.html.ep";} @{$app->renderer->paths;} or $c->app->renderer->get_data_template({"template", "$object/$key/$tab", "format", "html", "handler", "ep"})
grep {-e "$_/$object/$key/$tab.html.ep";} @{$app->renderer->paths;}
$c->app->renderer->get_data_template({"template", "$object/$key/$tab", "format", "html", "handler", "ep"})
Truth table0%0/3
A or B
A= grep {-e "$_/$object/$key/$tab.html.ep";} @{$app->renderer->paths;}B= $c->app->renderer->get_data_template({"template", "$object/$key/$tab", "format", "html", "handler", "ep"})
| |||||||||||||||||||||||||||||
| 312 | || $c->app->renderer->get_data_template( {template => "$object/$key/$tab", format => "html", handler => "ep"}) ) { | ||||||||||||||||||||||||||||
| 313 | 0 | $template = "$object/$key/$tab"; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | } else { | ||||||||||||||||||||||||||||
| 316 | 0 | $template = "none_selected"; | |||||||||||||||||||||||||||
| 317 | 0 | ▶ | $template = "$object/none_selected" if grep { -e "$_/$object/none_selected.html.ep" } @{ $app->renderer->paths }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | 0 | ▶ | $c->stash->{template} = $template || "single"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$template || 'single'
MC/DC0%0/1
$template || 'single'
$template
Truth table0%0/2
A
A= $template
| |||||||||||||||||||||||||||||
| 320 | 0 | my $instance = $c->current_instance; | |||||||||||||||||||||||||||
| 321 | 0 | $c->stash( instance => $instance ); | |||||||||||||||||||||||||||
| 322 | 0 | $c->stash( nav_item => $nav_item ); | |||||||||||||||||||||||||||
| 323 | 0 | $c->stash( $object => $instance ); | |||||||||||||||||||||||||||
| 324 | 0 | ▶ | $c->render unless $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 0 | ▶ | $key ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | 20 | )->any; | |||||||||||||||||||||||||||
| 328 | 20 | ▶ | $r = $r->to("$object#$tab") if $found_controller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 20 | $r->name("$object/$tab"); | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 2 | ▶ | sub _menu_to_nav { | ||||||||||||||||||||||||||
|
Subroutine
_menu_to_nav: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 333 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 334 | 2 | my ($conf,$menu) = @_; | |||||||||||||||||||||||||||
| 335 | 2 | my $nav; | |||||||||||||||||||||||||||
| 336 | my $sidebar; | ||||||||||||||||||||||||||||
| 337 | 2 | my $tabs; | |||||||||||||||||||||||||||
| 338 | 2 | my $object; | |||||||||||||||||||||||||||
| 339 | 2 | for (@$menu) { | |||||||||||||||||||||||||||
| 340 | 8 | ▶ | unless (ref $_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | 4 | $object = $_; | |||||||||||||||||||||||||||
| 342 | 4 | push @$nav, $object; | |||||||||||||||||||||||||||
| 343 | 4 | next; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | 4 | ▶ | for my $action (@{ $_->{many} || [] }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$_->{'many'} || []
MC/DC0%0/1
$_->{'many'} || []
$_->{'many'}
Truth table50%1/2
A
A= $_->{'many'}
| |||||||||||||||||||||||||||||
| 346 | 8 | push @{$sidebar->{$object}}, "$object/$action"; | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | 4 | push @{$sidebar->{$object}}, $object; | |||||||||||||||||||||||||||
| 349 | 4 | ▶ | for my $action (@{ $_->{one} || [] }) { | ||||||||||||||||||||||||||
|
Condition50%1/2
$_->{'one'} || []
MC/DC0%0/1
$_->{'one'} || []
$_->{'one'}
Truth table50%1/2
A
A= $_->{'one'}
| |||||||||||||||||||||||||||||
| 350 | 7 | push @{$tabs->{$object}}, $action; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | 2 | $conf->{nav} = $nav; | |||||||||||||||||||||||||||
| 354 | 2 | $conf->{sidebar} = $sidebar; | |||||||||||||||||||||||||||
| 355 | 2 | $conf->{tabs} = $tabs; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 4 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=19 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||
| 359 | 4 | my ($self, $app, $conf) = @_; | |||||||||||||||||||||||||||
| 360 | 4 | $app->log->debug("registering plugin"); | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 4 | ▶ | if (my $menu = $conf->{menu}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 2 | $self->_menu_to_nav($conf,$menu); | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | 4 | for (qw/nav sidebar tabs/) { | |||||||||||||||||||||||||||
| 366 | 12 | ▶ | die "missing $_" unless $conf->{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | 4 | my ($nav,$sidebar,$tabs) = @$conf{qw/nav sidebar tabs/}; | |||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 4 | ▶ | my $prefix = $conf->{prefix} || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{'prefix'} || ''
MC/DC0%0/1
$conf->{'prefix'} || ''
$conf->{'prefix'}
Truth table50%1/2
A
A= $conf->{'prefix'}
| |||||||||||||||||||||||||||||
| 371 | 4 | ▶ | my $routes = $conf->{head_route} || $app->routes; | ||||||||||||||||||||||||||
|
Condition33%1/3
$conf->{'head_route'} || $app->routes
MC/DC0%0/2
$conf->{'head_route'} || $app->routes
$conf->{'head_route'}
$app->routes
Truth table33%1/3
A || B
A= $conf->{'head_route'}B= $app->routes
| |||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 4 | my $base = catdir(abs_path(dirname(__FILE__)), qw/Toto Assets/); | |||||||||||||||||||||||||||
| 374 | 4 | my $default_path = catdir($base,'templates'); | |||||||||||||||||||||||||||
| 375 | 4 | push @{$app->renderer->paths}, catdir($base, 'templates'); | |||||||||||||||||||||||||||
| 376 | 4 | push @{$app->static->paths}, catdir($base, 'public'); | |||||||||||||||||||||||||||
| 377 | 4 | $app->defaults(layout => "toto", toto_prefix => $prefix); | |||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 4 | $app->log->debug("Adding routes"); | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 4 | my %tab_done; | |||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 4 | ▶ | die "toto plugin needs a 'nav' entry, please read the pod for more information" unless $nav; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 384 | 4 | for my $nav_item ( @$nav ) { | |||||||||||||||||||||||||||
| 385 | 8 | $app->log->debug("Adding routes for $nav_item"); | |||||||||||||||||||||||||||
| 386 | 8 | my $first; | |||||||||||||||||||||||||||
| 387 | 8 | ▶ | my $items = $sidebar->{$nav_item} or die "no sidebar for $nav_item"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 388 | 8 | for my $subnav_item ( @$items ) { | |||||||||||||||||||||||||||
| 389 | 23 | $app->log->debug("routes for $subnav_item"); | |||||||||||||||||||||||||||
| 390 | 23 | my ( $object, $action ) = split '/', $subnav_item; | |||||||||||||||||||||||||||
| 391 | 23 | ▶ | if ($action) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 14 | ▶ | $first ||= $subnav_item; | ||||||||||||||||||||||||||
|
Condition66%2/3
$first ||= $subnav_item
MC/DC0%0/2
$first ||= $subnav_item
$first
$subnav_item
Truth table66%2/3
A ||= B
A= $firstB= $subnav_item
| |||||||||||||||||||||||||||||
| 393 | 14 | $self->_add_sidebar($app,$routes,$prefix,$nav_item,$object,$action); | |||||||||||||||||||||||||||
| 394 | } else { | ||||||||||||||||||||||||||||
| 395 | 9 | my $first_tab; | |||||||||||||||||||||||||||
| 396 | 9 | ▶ | $first ||= "$object/default"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$first ||= "$object/default"
MC/DC0%0/1
$first ||= "$object/default"
$first
Truth table50%1/2
A
A= $first
| |||||||||||||||||||||||||||||
| 397 | my $tabs = $tabs->{$subnav_item} or | ||||||||||||||||||||||||||||
| 398 | 0 | ▶ | do { warn "# no tabs for $subnav_item"; next; }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 9 | ▶ | die "tab row for '$subnav_item' appears more than once" if $tab_done{$subnav_item}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | 9 | for my $tab (@$tabs) { | |||||||||||||||||||||||||||
| 401 | 20 | ▶ | $first_tab ||= $tab; | ||||||||||||||||||||||||||
|
Condition66%2/3
$first_tab ||= $tab
MC/DC0%0/2
$first_tab ||= $tab
$first_tab
$tab
Truth table66%2/3
A ||= B
A= $first_tabB= $tab
| |||||||||||||||||||||||||||||
| 402 | 20 | $self->_add_tab($app,$routes,$prefix,$nav_item,$object,$tab); | |||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||
| 404 | 9 | $app->log->debug("Will redirect $prefix/$object/default/key to $object/$first_tab/\$key"); | |||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 0 | ▶ | $routes->get("$prefix/$object/default/*key" => { key => '' } => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 407 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 408 | 0 | my $key = $c->stash("key"); | |||||||||||||||||||||||||||
| 409 | 0 | $c->redirect_to("$object/$first_tab", key => $key); | |||||||||||||||||||||||||||
| 410 | 9 | } => "$object/default"); | |||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | $routes->get( | ||||||||||||||||||||||||||||
| 413 | 0 | ▶ | "$prefix/$object/autocomplete" => { layout => "default" } => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 414 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 415 | 0 | my $query = $c->param('q'); | |||||||||||||||||||||||||||
| 416 | 0 | ▶ | return $c->render_not_found unless $c->model_class->can("autocomplete"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 417 | 0 | my $results = $c->model_class->autocomplete( q => $query, object => $object, c => $c, tab => $c->param('tab') ); | |||||||||||||||||||||||||||
| 418 | # Expects an array ref of the form | ||||||||||||||||||||||||||||
| 419 | # [ { name => 'foo', href => 'bar' }, ] | ||||||||||||||||||||||||||||
| 420 | 0 | $c->render( json => $results ); | |||||||||||||||||||||||||||
| 421 | 9 | } => "$object/autocomplete"); | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | 8 | ▶ | die "Could not find first route for nav item '$nav_item' : all entries have tabs\n" unless $first; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | $routes->get( | ||||||||||||||||||||||||||||
| 426 | 5 | ▶ | $nav_item => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 427 | 5 | my $c = shift; | |||||||||||||||||||||||||||
| 428 | 5 | $c->redirect_to($first); | |||||||||||||||||||||||||||
| 429 | 8 | } => $nav_item ); | |||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 4 | my $first_object = $conf->{nav}[0]; | |||||||||||||||||||||||||||
| 433 | 4 | ▶ | $routes->get("$prefix/" => sub { shift->redirect_to($first_object) } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 4 | for ($app) { | |||||||||||||||||||||||||||
| 436 | 4 | ▶ | $_->helper( toto_config => sub { $conf } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 437 | 0 | ▶ | $_->helper( model_class => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 438 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 439 | 0 | ▶ | if (my $ns = $conf->{model_namespace}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | 0 | return join '::', $ns, b($c->current_object)->camelize; | |||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | 0 | ▶ | $conf->{model_class} || "Mojolicious::Plugin::Toto::Model" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | 4 | ); | |||||||||||||||||||||||||||
| 445 | $_->helper( | ||||||||||||||||||||||||||||
| 446 | 8 | ▶ | tabs => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.6
| |||||||||||||||||||||||||||||
| 447 | 8 | my $c = shift; | |||||||||||||||||||||||||||
| 448 | 8 | ▶ | my $for = shift || $c->current_object or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
shift() || $c->current_object
MC/DC0%0/2
shift() || $c->current_object
shift()
$c->current_object
Truth table33%1/3
A || B
A= shift()B= $c->current_object
| |||||||||||||||||||||||||||||
| 449 | 8 | ▶ | @{ $conf->{tabs}{$for} || [] }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{'tabs'}{$for} || []
MC/DC0%0/1
$conf->{'tabs'}{$for} || []
$conf->{'tabs'}{$for}
Truth table50%1/2
A
A= $conf->{'tabs'}{$for}
| |||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | 4 | ); | |||||||||||||||||||||||||||
| 452 | 8 | ▶ | $_->helper( current_object => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 453 | 8 | my $c = shift; | |||||||||||||||||||||||||||
| 454 | 8 | ▶ | $c->stash('object') || [ split '\/', $c->current_route ]->[0] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 455 | 4 | } ); | |||||||||||||||||||||||||||
| 456 | 0 | ▶ | $_->helper( current_tab => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 457 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 458 | 0 | ▶ | $c->stash('tab') || [ split '\/', $c->current_route ]->[1] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | 4 | } ); | |||||||||||||||||||||||||||
| 460 | 0 | ▶ | $_->helper( current_instance => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 461 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 462 | 0 | ▶ | my $key = $c->stash("key") || [ split '\/', $c->current_route ]->[2]; | ||||||||||||||||||||||||||
|
Condition0%0/3
$c->stash('key') || [split(m[\/]u, $c->current_route, 0)]->[2]
MC/DC0%0/2
$c->stash('key') || [split(m[\/]u, $c->current_route, 0)]->[2]
$c->stash('key')
[split(m[\/]u, $c->current_route, 0)]->[2]
Truth table0%0/3
A || B
A= $c->stash('key')B= [split(m[\/]u, $c->current_route, 0)]->[2]
| |||||||||||||||||||||||||||||
| 463 | 0 | return $c->model_class->new(key => $key); | |||||||||||||||||||||||||||
| 464 | 4 | } ); | |||||||||||||||||||||||||||
| 465 | 16 | ▶ | $_->helper( printable => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 466 | 16 | my $c = shift; | |||||||||||||||||||||||||||
| 467 | 16 | my $what = shift; | |||||||||||||||||||||||||||
| 468 | 16 | $what =~ s/_/ /g; | |||||||||||||||||||||||||||
| 469 | 4 | $what } ); | |||||||||||||||||||||||||||
| 470 | 0 | ▶ | $_->helper( a_printable => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 471 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 472 | 0 | my $what = shift; | |||||||||||||||||||||||||||
| 473 | 0 | ▶ | return ( ($what =~ /^[aeiou]/ ? "an " : "a ").$c->printable($what)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 474 | 4 | } ); | |||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | 4 | $self; | |||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 4 | 1; | |||||||||||||||||||||||||||