| 1 | package CGI::Ex::Recipes::Template::Menu; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | #use CGI::Ex::Dump qw(debug dex_warn); | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 0 | ▶ | sub load { # called as Menu->load($context) | ||||||||||||||||||
|
Subroutine
load: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 13 | 0 | my ( $class, $context ) = @_; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | #we may do other things beside just returning the class name if we need. | ||||||||||||||||||||
| 16 | 0 | return $class; # returns 'Menu' | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | ▶ | sub new { # called as Menu->new($context) | ||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 20 | 0 | my ( $class, $context, @params ) = @_; | |||||||||||||||||||
| 21 | 0 | bless { | |||||||||||||||||||
| 22 | _CONTEXT => $context, | ||||||||||||||||||||
| 23 | _PARAMS => $params[0], | ||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||
| 25 | $class; # returns blessed Menu object | ||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | sub run { | ||||||||||||||||||
|
Subroutine
run: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 29 | 0 | my ( $self, @args ) = @_; | |||||||||||||||||||
| 30 | 0 | ▶ | if ( $args[0] == 'default_map' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 0 | return 'hi '; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | 0 | return $self->{_CONTEXT}->stash->get('app'); | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | #================METHODS CALLABLE FROM OUTSIDE================ | ||||||||||||||||||||
| 37 | #lists only item in the current category $id | ||||||||||||||||||||
| 38 | 0 | ▶ | sub list_item { | ||||||||||||||||||
|
Subroutine
list_item: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||
| 40 | 0 | ▶ | my $item = shift || die('please provide a recipe item.') . $!; | ||||||||||||||||||
|
Condition0%0/2
shift() || die('please provide a recipe item.')
MC/DC0%0/1
shift() || die('please provide a recipe item.')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 41 | 0 | ▶ | my $app = $self->{app} ||= $self->get('app'); | ||||||||||||||||||
|
Condition0%0/3
$self->{"app"} ||= $self->get("app")
MC/DC0%0/2
$self->{"app"} ||= $self->get("app")
$self->{"app"}
$self->get("app")
Truth table0%0/3
A ||= B
A= $self->{"app"}B= $self->get("app")
| |||||||||||||||||||||
| 42 | 0 | my $cgix = $app->cgix; | |||||||||||||||||||
| 43 | 0 | my $out; | |||||||||||||||||||
| 44 | 0 | ▶ | my $cache_key = 'list_item_' . $item->{id} . ( $app->is_authed ? 1 : '' ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | #try cache support | ||||||||||||||||||||
| 46 | 0 | ▶ | if( $out = $app->cache->get($cache_key) ){ return $out; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 0 | ▶ | if ( $self->{'recurse_level'} >= $self->{'_PARAMS'}{recurse} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 0 | return $cgix->li( { class => 'recipes', style => 'color:red' }, | |||||||||||||||||||
| 49 | 'Max recursion reached. ' . 'If you want more: USE menu = Menu(recurse => 10000);' ); | ||||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | if ( $item->{is_category} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 0 | $self->{'recurse_level'}++;#ТОДО:make it work | |||||||||||||||||||
| 54 | 0 | foreach my $list_item ( | |||||||||||||||||||
| 55 | @{ $app->recipes( | ||||||||||||||||||||
| 56 | [qw(id pid is_category title)], | ||||||||||||||||||||
| 57 | { pid => $item->{id}, | ||||||||||||||||||||
| 58 | id => { '!=', $item->{id} }, | ||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||
| 60 | 0 | ['sortorder'] | |||||||||||||||||||
| 61 | ) | ||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | ) | ||||||||||||||||||||
| 64 | { | ||||||||||||||||||||
| 65 | 0 | $out .= $self->list_item($list_item); | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | $out = $cgix->li( | ||||||||||||||||||||
| 68 | { class => 'recipes' }, | ||||||||||||||||||||
| 69 | ( $app->is_authed | ||||||||||||||||||||
| 70 | ? $cgix->a( | ||||||||||||||||||||
| 71 | { class => 'delete right', | ||||||||||||||||||||
| 72 | href => $app->script_name . '/delete/' . $item->{id} | ||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||
| 74 | 'delete' | ||||||||||||||||||||
| 75 | ) | ||||||||||||||||||||
| 76 | . $cgix->a( | ||||||||||||||||||||
| 77 | { class => 'edit right', | ||||||||||||||||||||
| 78 | href => $app->script_name . '/edit/' . $item->{id} | ||||||||||||||||||||
| 79 | }, | ||||||||||||||||||||
| 80 | 'edit' | ||||||||||||||||||||
| 81 | ) | ||||||||||||||||||||
| 82 | . $cgix->a( | ||||||||||||||||||||
| 83 | { class => 'add right', | ||||||||||||||||||||
| 84 | href => $app->script_name . '/add/' . $item->{id} | ||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||
| 86 | 'add here' | ||||||||||||||||||||
| 87 | ) | ||||||||||||||||||||
| 88 | : '' | ||||||||||||||||||||
| 89 | ) | ||||||||||||||||||||
| 90 | . $cgix->a( { href => $app->script_name . '/view/' . $item->{id} }, $item->{title} ) | ||||||||||||||||||||
| 91 | 0 | ▶ | ) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 92 | . ( $out ? $cgix->ul( { class => 'recipes' }, $out ) : '' ); | ||||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||
| 95 | $out = $cgix->li( | ||||||||||||||||||||
| 96 | { class => 'recipes' }, | ||||||||||||||||||||
| 97 | ( $app->is_authed | ||||||||||||||||||||
| 98 | ? $cgix->a( | ||||||||||||||||||||
| 99 | { class => 'delete right', | ||||||||||||||||||||
| 100 | href => $app->script_name . '/delete/' . $item->{id} . '/pid/'. $item->{pid} | ||||||||||||||||||||
| 101 | }, | ||||||||||||||||||||
| 102 | 'delete' | ||||||||||||||||||||
| 103 | ) | ||||||||||||||||||||
| 104 | . $cgix->a( | ||||||||||||||||||||
| 105 | { class => 'edit right', | ||||||||||||||||||||
| 106 | href => $app->script_name . '/edit/' . $item->{id} | ||||||||||||||||||||
| 107 | }, | ||||||||||||||||||||
| 108 | 'edit' | ||||||||||||||||||||
| 109 | ) | ||||||||||||||||||||
| 110 | . $cgix->a( | ||||||||||||||||||||
| 111 | { class => 'add right', | ||||||||||||||||||||
| 112 | href => $app->script_name . '/add/' . $item->{pid} . '/after/' . $item->{id} | ||||||||||||||||||||
| 113 | }, | ||||||||||||||||||||
| 114 | 'add after' | ||||||||||||||||||||
| 115 | ) | ||||||||||||||||||||
| 116 | : '' | ||||||||||||||||||||
| 117 | ) | ||||||||||||||||||||
| 118 | . $cgix->a( { href => $app->script_name . '/view/' . $item->{id} }, $item->{title} ) | ||||||||||||||||||||
| 119 | 0 | ▶ | ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | #try cache support | ||||||||||||||||||||
| 122 | 0 | $app->cache->set($cache_key, $out); | |||||||||||||||||||
| 123 | 0 | return $out; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | #called in default.tthtml. | ||||||||||||||||||||
| 128 | #lists all categorie under $id and items within them | ||||||||||||||||||||
| 129 | 0 | ▶ | sub recipes_map { | ||||||||||||||||||
|
Subroutine
recipes_map: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||
| 130 | 0 | my $self = shift; | |||||||||||||||||||
| 131 | 0 | ▶ | my $id = shift || 0; #id from which to start. must be a category id or 0(Top) | ||||||||||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 132 | 0 | my $out = ''; # we will push HTML here | |||||||||||||||||||
| 133 | 0 | $self->{'recurse_level'} = 0; | |||||||||||||||||||
| 134 | 0 | ▶ | my $app = $self->{app} ||= $self->get('app'); | ||||||||||||||||||
|
Condition0%0/3
$self->{"app"} ||= $self->get("app")
MC/DC0%0/2
$self->{"app"} ||= $self->get("app")
$self->{"app"}
$self->get("app")
Truth table0%0/3
A ||= B
A= $self->{"app"}B= $self->get("app")
| |||||||||||||||||||||
| 135 | 0 | ▶ | my $cache_key = 'recipes_map_'. $id . ( $app->is_authed ? 1 : '' ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 136 | #try cache support | ||||||||||||||||||||
| 137 | 0 | ▶ | if( $out = $app->cache->get($cache_key) ){ return $out; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 138 | 0 | foreach my $item ( @{ $app->recipes( undef, { pid => $id } ) } ) { | |||||||||||||||||||
| 139 | 0 | $out .= $self->list_item($item); | |||||||||||||||||||
| 140 | } | ||||||||||||||||||||
| 141 | 0 | my $cgix = $app->cgix; | |||||||||||||||||||
| 142 | 0 | ▶ | $out = $cgix->ul( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 143 | { class => 'recipes' }, | ||||||||||||||||||||
| 144 | $cgix->li( | ||||||||||||||||||||
| 145 | { class => 'recipes' }, | ||||||||||||||||||||
| 146 | ( $app->is_authed | ||||||||||||||||||||
| 147 | ? $cgix->a( | ||||||||||||||||||||
| 148 | { class => 'add right', | ||||||||||||||||||||
| 149 | href => $app->script_name . '/add/' | ||||||||||||||||||||
| 150 | }, | ||||||||||||||||||||
| 151 | 'add' | ||||||||||||||||||||
| 152 | ) | ||||||||||||||||||||
| 153 | . ' ' | ||||||||||||||||||||
| 154 | : '' | ||||||||||||||||||||
| 155 | ) | ||||||||||||||||||||
| 156 | ) | ||||||||||||||||||||
| 157 | . $out | ||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||
| 159 | #try cache support | ||||||||||||||||||||
| 160 | 0 | $app->cache->set($cache_key, $out); | |||||||||||||||||||
| 161 | 0 | return $out; | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | #====================METHODS USED INTERNALLY================== | ||||||||||||||||||||
| 165 | #shows controls for add,edit,delete if user is_authed | ||||||||||||||||||||
| 166 | 0 | ▶ | sub controls { | ||||||||||||||||||
|
Subroutine
controls: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | 0 | ▶ | sub context { $_[0]->{_CONTEXT} } | ||||||||||||||||||
|
Subroutine
context: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 171 | 0 | ▶ | sub stash { $_[0]->{_CONTEXT}->stash } | ||||||||||||||||||
|
Subroutine
stash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 172 | 0 | ▶ | sub get { shift->stash->get(@_) } | ||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 173 | 0 | ▶ | sub set { shift->stash->set(@_) } | ||||||||||||||||||
|
Subroutine
set: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | 1 | 1; # End of CGI::Ex::Recipes::Template::Menu | |||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||