| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CGI::Ex::Recipes::Template::Menu; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1170
|
use utf8; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
6
|
|
|
4
|
1
|
|
|
1
|
|
35
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1100
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#use CGI::Ex::Dump qw(debug dex_warn); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub load { # called as Menu->load($context) |
|
13
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub new { # called as Menu->new($context) |
|
20
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub run { |
|
29
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
|
30
|
0
|
0
|
|
|
|
|
if ( $args[0] == 'default_map' ) { |
|
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
|
|
|
|
|
|
|
sub list_item { |
|
39
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
40
|
0
|
|
0
|
|
|
|
my $item = shift || die('please provide a recipe item.') . $!; |
|
41
|
0
|
|
0
|
|
|
|
my $app = $self->{app} ||= $self->get('app'); |
|
42
|
0
|
|
|
|
|
|
my $cgix = $app->cgix; |
|
43
|
0
|
|
|
|
|
|
my $out; |
|
44
|
0
|
0
|
|
|
|
|
my $cache_key = 'list_item_' . $item->{id} . ( $app->is_authed ? 1 : '' ); |
|
45
|
|
|
|
|
|
|
#try cache support |
|
46
|
0
|
0
|
|
|
|
|
if( $out = $app->cache->get($cache_key) ){ return $out; } |
|
|
0
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if ( $self->{'recurse_level'} >= $self->{'_PARAMS'}{recurse} ) { |
|
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
|
0
|
|
|
|
|
if ( $item->{is_category} ) { |
|
53
|
0
|
|
|
|
|
|
$self->{'recurse_level'}++;#ТОДО:make it work |
|
54
|
0
|
|
|
|
|
|
foreach my $list_item ( |
|
|
0
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
@{ $app->recipes( |
|
56
|
|
|
|
|
|
|
[qw(id pid is_category title)], |
|
57
|
|
|
|
|
|
|
{ pid => $item->{id}, |
|
58
|
|
|
|
|
|
|
id => { '!=', $item->{id} }, |
|
59
|
|
|
|
|
|
|
}, |
|
60
|
|
|
|
|
|
|
['sortorder'] |
|
61
|
|
|
|
|
|
|
) |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
) |
|
64
|
|
|
|
|
|
|
{ |
|
65
|
0
|
|
|
|
|
|
$out .= $self->list_item($list_item); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
0
|
|
|
|
|
$out = $cgix->li( |
|
|
|
0
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
) |
|
92
|
|
|
|
|
|
|
. ( $out ? $cgix->ul( { class => 'recipes' }, $out ) : '' ); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
else { |
|
95
|
0
|
0
|
|
|
|
|
$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
|
|
|
|
|
|
|
); |
|
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
|
|
|
|
|
|
|
sub recipes_map { |
|
130
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
131
|
0
|
|
0
|
|
|
|
my $id = shift || 0; #id from which to start. must be a category id or 0(Top) |
|
132
|
0
|
|
|
|
|
|
my $out = ''; # we will push HTML here |
|
133
|
0
|
|
|
|
|
|
$self->{'recurse_level'} = 0; |
|
134
|
0
|
|
0
|
|
|
|
my $app = $self->{app} ||= $self->get('app'); |
|
135
|
0
|
0
|
|
|
|
|
my $cache_key = 'recipes_map_'. $id . ( $app->is_authed ? 1 : '' ); |
|
136
|
|
|
|
|
|
|
#try cache support |
|
137
|
0
|
0
|
|
|
|
|
if( $out = $app->cache->get($cache_key) ){ return $out; } |
|
|
0
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
foreach my $item ( @{ $app->recipes( undef, { pid => $id } ) } ) { |
|
|
0
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$out .= $self->list_item($item); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
0
|
|
|
|
|
|
my $cgix = $app->cgix; |
|
142
|
0
|
0
|
|
|
|
|
$out = $cgix->ul( |
|
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
|
|
|
0
|
0
|
|
sub controls { |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
|
|
0
|
0
|
|
sub context { $_[0]->{_CONTEXT} } |
|
171
|
0
|
|
|
0
|
0
|
|
sub stash { $_[0]->{_CONTEXT}->stash } |
|
172
|
0
|
|
|
0
|
0
|
|
sub get { shift->stash->get(@_) } |
|
173
|
0
|
|
|
0
|
0
|
|
sub set { shift->stash->set(@_) } |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; # End of CGI::Ex::Recipes::Template::Menu |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
__END__ |