Catalyst.pm

filter: Statementstmt 21.5% 41 / 190 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 36.1% 13 / 36 Podpod 100% 7 / 7 totaltotal 21.3% 61 / 286 CC 27 SCAR 46.7
CC
27
Cov
17%
make_catalyst
342.0
_make_menu_items
42.0
_write_tt_file
30.0
CRAP 106.6
↑ Summary Catalyst/Controller.pm »
1 package Rose::DBx::Garden::Catalyst;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base qw( Rose::DBx::Garden );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Data::Dump qw( dump );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Tree::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Tree::Simple::Visitor::ToNestedHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Class::Inspector;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use CatalystX::CRUD::YUI::TT;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use File::Slurp::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use Rose::Object::MakeMethods::Generic (
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 'scalar --get_set_init' => [qw( catalyst_prefix controller_prefix )],
18 boolean => [ 'tt' => { default => 1 }, ]
19 2 );
20  
21 2 our $VERSION = '0.180';
22  
23 =head1 NAME
24  
25 Rose::DBx::Garden::Catalyst - plant Roses in your Catalyst garden
26  
27 =head1 SYNOPSIS
28  
29 # create a Catalyst app
30 > catalyst.pl MyApp
31
32 # create a Rose::DBx::Garden::Catalyst script
33 > cat mk_cat_garden.pl
34 use Rose::DBx::Garden::Catalyst;
35 use MyDB; # isa Rose::DB
36
37 my $garden = Rose::DBx::Garden::Catalyst->new(
38 catalyst_prefix => 'MyApp',
39 controller_prefix => 'RDGC',
40 garden_prefix => 'MyRDBO',
41 db => MyDB->new,
42 tt => 1, # make Template Toolkit files
43 );
44
45 $garden->plant('MyApp/lib');
46
47 # run your script
48 > perl mk_cat_garden.pl
49
50 # edit your MyApp.pm file:
51 > vi MyApp/lib/MyApp.pm
52
53 # serve static assets
54 use Catalyst qw/
55 Static::Simple::ByClass
56 /;
57
58 __PACKAGE__->config(
59 'Plugin::Static::Simple::ByClass' => {
60 classes => [qw( CatalystX::CRUD::YUI::TT )],
61 }
62 'default_view' => 'RDGC',
63 );
64
65 # after __PACKAGE__->setup();
66 # add these lines:
67
68 use MRO::Compat;
69 use mro 'c3';
70 Class::C3::initialize();
71
72 # start your Catalyst dev server
73 > cd MyApp
74 > perl script/myapp_server.pl
75
76 # enjoy the fruits at http://localhost:3000/rdgc
77  
78 =head1 DESCRIPTION
79  
80 Rose::DBx::Garden::Catalyst extends Rose::DBx::Garden to create
81 Catalyst component scaffolding. These created components use the RDBO
82 and RHTMLO classes that the Garden class produces. The base
83 Controller, Model and View classes are simple subclasses of
84 CatalystX::CRUD::YUI.
85  
86 This module works on the assumption that 1 table == 1 form == 1 controller class == 1 model class.
87  
88 By default this class creates stub Template Toolkit files for use
89 with the RDBO and RHTMLO CRUD components. If you use a different templating
90 system, just set the C<tt> option to 0.
91  
92 =head1 METHODS
93  
94 Only new or overridden methods are documented here.
95  
96 =cut
97  
98 =head2 init_controller_prefix
99  
100 The namespace where Catalyst Controllers are created. Will also be lowercased
101 and serve as the URI path namespace for all RDGC actions.
102  
103 Default: RDGC
104  
105 =cut
106  
107 0 ▶sub init_controller_prefix {'RDGC'}
Subroutine init_controller_prefix: not called CC=1 SCAR=6.9
Pod documented
108  
109 =head2 init_base_code
110  
111 Override the base method to create methods useful to RDBO classes
112 used in Catalyst.
113  
114 =cut
115  
116 0 ▶sub init_base_code {
Subroutine init_base_code: not called CC=1 SCAR=6.9
Pod documented
117 0 return <<EOF;
118  
119 use base qw( Rose::DBx::Garden::Catalyst::Object );
120  
121 EOF
122 }
123  
124 =head2 init_base_form_class_code
125  
126 Custom base Form code to implement features that template will require.
127  
128 =cut
129  
130 0 ▶sub init_base_form_class_code {
Subroutine init_base_form_class_code: not called CC=1 SCAR=6.9
Pod documented
131 0 my $self = shift;
132 0 my $controller_prefix = $self->controller_prefix;
133 0 return <<EOF;
134 use Carp;
135 use base qw( Rose::DBx::Garden::Catalyst::Form );
136  
137 sub init_metadata {
138 my \$self = shift;
139 return \$self->metadata_class->new(
140 form => \$self,
141 controller_prefix => '$controller_prefix',
142 );
143 }
144  
145 EOF
146 }
147  
148 =head2 init_catalyst_prefix
149  
150 Defaults to 'MyApp'.
151  
152 =cut
153  
154 0 ▶sub init_catalyst_prefix {'MyApp'}
Subroutine init_catalyst_prefix: not called CC=1 SCAR=6.9
Pod documented
155  
156 =head2 base_tt_path
157  
158 Returns controller_prefix() transformed to a file path.
159  
160 =cut
161  
162 0 ▶sub base_tt_path {
Subroutine base_tt_path: not called CC=1 SCAR=6.9
Pod documented
163 0 my $self = shift;
164 0 my $cp = $self->controller_prefix;
165 0 $cp =~ s,::,/,g;
166 0 return lc($cp);
167 }
168  
169 =head2 plant( I<path/to/my/catapp> )
170  
171 Override the base method to create Catalyst-related files in addition
172 to the basic Garden files.
173  
174 =cut
175  
176 0 ▶sub plant {
Subroutine plant: not called CC=1 SCAR=6.9
Pod documented
177 0 my $self = shift;
178 0 my $garden = $self->SUPER::plant(@_);
179 0 $self->make_catalyst( $garden, $self->module_dir );
180 }
181  
182 =head2 make_catalyst( I<class_names>, I<path> )
183  
184 Does the actual file creation of Catalyst files. Called by plant().
185  
186 I<class_names> should be a hash ref of RDBO => RHTMLO class names, as returned
187 by Rose::DBx::Garden->plant(). If you have existing RDBO and RHTMLO classes
188 that have namespaces inconsistent with the conventions in Rose::DBx::Garden,
189 they B<should> still work. Just map the RDBO => RHTMLO classes in your
190 I<class_names> hash ref.
191  
192 =cut
193  
194 0 ▶sub make_catalyst {
Subroutine make_catalyst: not called CC=18 SCAR=58.3
Pod documented
195 0 my $self = shift;
196 0 ▶ my $garden = shift or croak "hash of class names required";
Branch: 1 branch
BranchTrueFalseTotal
my $garden = shift() or croak("hash of class names required") 0 0 0
197 0 ▶ my $path = shift or croak "path required";
Branch: 1 branch
BranchTrueFalseTotal
my $path = shift() or croak("path required") 0 0 0
198 0 ▶ unless ( ref($garden) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $garden eq "HASH") 0 0 0
199 0 croak "class_names must be a HASH ref";
200 }
201 0 my %rhtmlo2rdbo = reverse %$garden;
202 0 delete $rhtmlo2rdbo{1};
203 0 my @form_classes = keys %rhtmlo2rdbo;
204  
205 # make sure this looks like a Catalyst dir.
206 # use same criteria as the Catalst
207 # path_to() method: Makefile.PL or Build.PL
208 0 my $dir = dir($path);
209 0 my $root = $dir->parent;
210 0 ▶ unless ( -f $root->file('Makefile.PL') or -f $root->file('Build.PL') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $root->file("Makefile.PL") or -f $root->file("Build.PL")) 0 0 0
Condition0%0/3
-f $root->file("Makefile.PL") or -f $root->file("Build.PL")
l!l&&r!l&&!r
000
MC/DC0%0/2
-f $root->file("Makefile.PL") or -f $root->file("Build.PL")
-f $root->file("Makefile.PL") -f $root->file("Build.PL")
Truth table0%0/3
A or B
A= -f $root->file("Makefile.PL")B= -f $root->file("Build.PL")
ABresult
1X1
011
000
211 0 croak "$root does not look like a Catalyst application directory "
212 . "(no Makefile.PL or Build.PL file)";
213 }
214  
215 # make CRUD controllers and models for each Form class.
216 # we only care about Form classes because those do not
217 # represent map classes, which should be invisible to normal usage.
218  
219 0 my $catprefix = $self->catalyst_prefix;
220 0 my $gardprefix = $self->garden_prefix;
221 0 my $controller_prefix = $self->controller_prefix;
222 0 my @controllers;
223 my %tree;
224  
225 # parent controller
226 0 $self->_make_file(
227 join( '::', $catprefix, 'Controller', $controller_prefix ),
228 $self->_make_parent_controller );
229  
230 # our TT View
231 0 $self->_make_file( join( '::', $catprefix, 'View', 'RDGC' ),
232 $self->_make_view );
233  
234 # our Excel export View
235 0 $self->_make_file( join( '::', $catprefix, 'View', 'Excel' ),
236 $self->_make_excel_view );
237  
238 # base Controller and Model classes
239 0 $self->_make_file(
240 join( '::', $catprefix, 'Base', 'Controller', 'RHTMLO' ),
241 $self->_make_base_rhtmlo_controller );
242 0 $self->_make_file( join( '::', $catprefix, 'Base', 'Model', 'RDBO' ),
243 $self->_make_base_rdbo_model );
244  
245 # sort so menu comes out sorted
246 0 for my $rhtmlo ( sort @form_classes ) {
247 0 my $rdbo = $rhtmlo2rdbo{$rhtmlo};
248 0 my $bare = $rdbo;
249 0 $bare =~ s/^${gardprefix}:://;
250 0 my $controller_class
251 = join( '::', $catprefix, 'Controller', $controller_prefix,
252 $bare );
253 0 my $model_class
254 = join( '::', $catprefix, 'Model', $controller_prefix, $bare );
255 0 $self->_make_file(
256 $controller_class,
257 $self->_make_controller(
258 $rdbo, $rhtmlo, $controller_class, $model_class
259 )
260 );
261 0 $self->_make_file( $model_class,
262 $self->_make_model( $model_class, $rdbo ) );
263 0 push( @controllers, $controller_class );
264  
265 # create menus, split by :: into flyout levels (max 4 deep)
266 0 my (@parts) = split( m/::/, $bare );
267 0 my $top = shift @parts;
268 $tree{$top} = Tree::Simple->new( $top, Tree::Simple->ROOT )
269 0 ▶ unless exists $tree{$top};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tree{$top} 0 0 0
270 0 my $prev = $tree{$top};
271 0 for my $part (@parts) {
272 0 Tree::Simple->new( $part, $prev );
273 0 $prev = $part;
274 }
275 }
276  
277 0 my $base_url = $self->base_tt_path;
278  
279 0 my @menu_items = ( { href => '/' . $base_url, txt => 'Home' } );
280 0 for my $branch ( sort keys %tree ) {
281 0 my $visitor = Tree::Simple::Visitor::ToNestedHash->new();
282 0 my $subtree = $tree{$branch};
283 0 $subtree->accept($visitor);
284 0 my $m = $visitor->getResults();
285 0 my $children = $m->[0];
286 0 my %item;
287 0 $item{href} = join( '/', '', $base_url, lc($branch) );
288 0 $item{txt} = $branch;
289 0 my $sub = $self->_make_menu_items( $item{href}, $children );
290 0 ▶ $item{items} = $sub if $sub;
Branch: 1 branch
BranchTrueFalseTotal
if $sub 0 0 0
291 0 push( @menu_items, \%item );
292 }
293  
294 # populate templates
295 # the idea is to create a 'crud' dir in MyApp/root/
296 # with the PROCESS-able .tt files
297 # and then add stub .tt files in each _tmpl_path
298 # for the CRUD methods
299  
300 # convention is template dir called 'root'
301 0 my $tt_dir = dir( $root, 'root' );
302 0 ▶ unless ( -d $tt_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $tt_dir) 0 0 0
303 0 croak "$tt_dir does not exist -- cannot create template files";
304 }
305  
306 # we need 1 dir, possibly 2
307 0 my $rdgc_tt_dir = dir( $tt_dir, 'crud' ); # used to be 'rdgc'
308 0 my $base_tt_dir = dir( $tt_dir, $base_url );
309 0 $rdgc_tt_dir->mkpath(1);
310 0 $base_tt_dir->mkpath(1);
311  
312 # write a default welcome page
313 0 $self->_write_tt_file( file( $base_tt_dir, 'default.tt' )->stringify,
314 $self->_tt_default_page );
315  
316 # write the menu now that we know the dir exists
317 0 $self->_write_tt_file(
318 file( $rdgc_tt_dir, 'schema_menu.tt' )->stringify,
319 '[% SET menu = '
320 . dump( { id => 'schema_menu', items => \@menu_items } ) . '%]'
321 );
322  
323 # disable stubs for each controller to reduce noise
324 # now that CatalystX::CRUD::YUI::View will serve the default .tt
325 #
326 # stubs for each controller
327 #for my $ctrl (@controllers) {
328 # my @tmpl_dir = $self->_tmpl_path_from_controller($ctrl);
329 #
330 # for my $stub (qw( search edit view list count )) {
331 # my $method = '_tt_stub_' . $stub;
332 # $self->_write_tt_file(
333 # file( $tt_dir, @tmpl_dir, $stub . '.tt' )->stringify,
334 # $self->$method );
335 # }
336 # }
337  
338 # css and js will not work out of the box anymore since
339 # they are in the CatalystX::CRUD::YUI package.
340 # so find them and copy them locally so that Static::Simple
341 # can find them.
342 0 my $cx_crud_yui_tt_path
343 = Class::Inspector->loaded_filename('CatalystX::CRUD::YUI::TT');
344 0 $cx_crud_yui_tt_path =~ s/\.pm//;
345  
346 0 my $js_dir = dir( $tt_dir, 'static', 'js' );
347 0 $js_dir->mkpath(1);
348 0 my $css_dir = dir( $tt_dir, 'static', 'css' );
349 0 $css_dir->mkpath(1);
350 0 my $css_crud_dir = dir( $css_dir, 'crud' );
351 0 $css_crud_dir->mkpath(1);
352  
353 0 ▶ copy( file( $cx_crud_yui_tt_path, 'static', 'js', 'crud.js' ) . '',
Branch: 1 branch
BranchTrueFalseTotal
copy(file($cx_crud_yui_tt_path, "static", "js", "crud.js") . '', file($js_dir, "crud.js") . '') or warn "ERROR: failed to copy crud.js to local static/js\n" 0 0 0
354 file( $js_dir, 'crud.js' ) . '' )
355 or warn "ERROR: failed to copy crud.js to local static/js\n";
356 0 ▶ copy( file( $cx_crud_yui_tt_path, 'static', 'js', 'json.js' ) . '',
Branch: 1 branch
BranchTrueFalseTotal
copy(file($cx_crud_yui_tt_path, "static", "js", "json.js") . '', file($js_dir, "json.js") . '') or warn "ERROR: failed to copy json.js to local static/js\n" 0 0 0
357 file( $js_dir, 'json.js' ) . '' )
358 or warn "ERROR: failed to copy json.js to local static/js\n";
359 0 ▶ copy( file( $cx_crud_yui_tt_path, 'static', 'css', 'crud.css' ) . '',
Branch: 1 branch
BranchTrueFalseTotal
copy(file($cx_crud_yui_tt_path, "static", "css", "crud.css") . '', file($css_dir, "crud.css") . '') or warn "ERROR: failed to copy crud.css to local static/css\n" 0 0 0
360 file( $css_dir, 'crud.css' ) . '' )
361 or warn "ERROR: failed to copy crud.css to local static/css\n";
362  
363 # all the css files
364 0 my $css_base_dir = dir( $cx_crud_yui_tt_path, 'static', 'css', 'crud' );
365 0 ▶ while ( my $css_file = $css_base_dir->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $css_file = $css_base_dir->next) 0 0 0
366 0 ▶ next unless -f $css_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $css_file 0 0 0
367 0 ▶ copy( $css_file . '',
Branch: 1 branch
BranchTrueFalseTotal
copy($css_file . '', file($css_crud_dir, $css_file->basename) . '') or warn "ERROR: failed to copy $css_file to $css_crud_dir\n" 0 0 0
368 file( $css_crud_dir, $css_file->basename ) . '' )
369 or warn "ERROR: failed to copy $css_file to $css_crud_dir\n";
370 }
371  
372 0 return $garden;
373 }
374  
375 0 ▶sub _make_menu_items {
Subroutine _make_menu_items: not called CC=6 SCAR=37.4
376 0 my ( $self, $parent, $children ) = @_;
377 0 ▶ return unless $children && keys %$children;
Branch: 1 branch
BranchTrueFalseTotal
unless $children and keys %$children 0 0 0
Condition0%0/3
$children and keys %$children
!ll&&!rl&&r
000
MC/DC0%0/2
$children and keys %$children
$children keys %$children
Truth table0%0/3
A and B
A= $childrenB= keys %$children
ABresult
0X0
100
111
378  
379 #carp "parent = $parent";
380 #carp dump $children;
381  
382 0 my @items;
383  
384 0 for my $child ( sort keys %$children ) {
385 0 my %item;
386 0 $item{href} = join( '/', $parent, lc($child) );
387 0 $item{txt} = $child;
388 0 ▶ if ( keys %{ $children->{$child} } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (keys %{$$children{$child};}) { } 0 0 0
elsif (not $child =~ /^(Search|Create|List)$/) { } 0 0 0
389 $item{items}
390 0 = $self->_make_menu_items( $item{href}, $children->{$child} );
391 }
392 elsif ( $child !~ m/^(Search|Create|List)$/ ) {
393 $item{items} = $self->_make_menu_items( $item{href},
394 0 { Search => {}, Create => {}, List => {} } );
395 }
396 0 push( @items, \%item );
397 }
398 0 return \@items;
399 }
400  
401 0 ▶sub _write_tt_file {
Subroutine _write_tt_file: not called CC=5 SCAR=34.0
402 0 my ( $self, $tt, $buf, $ext ) = @_;
403 0 ▶ my ( $name, $path, $suffix )
Condition0%0/3
$ext || qr/\.tt/
l!l&&r!l&&!r
000
MC/DC0%0/2
$ext || qr/\.tt/
$ext qr/\.tt/
Truth table0%0/3
A || B
A= $extB= qr/\.tt/
ABresult
1X1
011
000
404 = File::Basename::fileparse( $tt, $ext || qr{\.tt} );
405  
406 0 $path = dir($path);
407  
408 0 ▶ unless ( $self->force_install ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->force_install) 0 0 0
409 0 ▶ return if -s $tt;
Branch: 1 branch
BranchTrueFalseTotal
if -s $tt 0 0 0
410 }
411  
412 0 ▶ $path->mkpath(1) if $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path 0 0 0
413  
414 0 print "writing $tt\n";
415 0 File::Slurp::Tiny::write_file( $tt, $buf ); # Garden.pm uses File::Slurp::Tiny
416 }
417  
418 0 ▶sub _tt_default_page {
Subroutine _tt_default_page: not called CC=1 SCAR=6.9
419 0 return <<EOF;
420 Edit the root/rdgc/default page to change this content.
421 EOF
422 }
423  
424 0 ▶sub _tt_stub_search {
Subroutine _tt_stub_search: not called CC=1 SCAR=6.9
425 0 return <<EOF;
426 [% PROCESS rdgc/search.tt %]
427 EOF
428 }
429  
430 0 ▶sub _tt_stub_list {
Subroutine _tt_stub_list: not called CC=1 SCAR=6.9
431 0 return <<EOF;
432 [% PROCESS rdgc/list.tt %]
433 EOF
434 }
435  
436 0 ▶sub _tt_stub_count {
Subroutine _tt_stub_count: not called CC=1 SCAR=6.9
437 0 return <<EOF;
438 [% PROCESS rdgc/list.tt %]
439 EOF
440 }
441  
442 0 ▶sub _tt_stub_edit {
Subroutine _tt_stub_edit: not called CC=1 SCAR=6.9
443 0 return <<EOF;
444 [%
445 fields = {};
446 fields.readonly = {'created' = 1, 'modified' = 1}; # common auto-timestamp names
447 PROCESS rdgc/edit.tt;
448 %]
449 EOF
450 }
451  
452 0 ▶sub _tt_stub_view {
Subroutine _tt_stub_view: not called CC=1 SCAR=6.9
453 0 return <<EOF;
454 [%
455 fields = {};
456 fields.readonly = {};
457 FOREACH f IN form.field_names;
458 fields.readonly.\$f = 1;
459 END;
460 PROCESS rdgc/edit.tt buttons = 0;
461 %]
462 EOF
463 }
464  
465 0 ▶sub _tmpl_path_from_controller {
Subroutine _tmpl_path_from_controller: not called CC=1 SCAR=6.9
466 0 my ( $self, $controller ) = @_;
467 0 $controller =~ s/^.*::Controller:://;
468 0 return ( map { lc($_) } split( m/::/, $controller ) );
469 }
470  
471 0 ▶sub _make_parent_controller {
Subroutine _make_parent_controller: not called CC=1 SCAR=6.9
472 0 my $self = shift;
473 0 my $cat_class = $self->catalyst_prefix;
474 0 my $controller_prefix = $self->controller_prefix;
475 0 my $base_path = $self->base_tt_path;
476  
477 0 return <<EOF;
478 package ${cat_class}::Controller::${controller_prefix};
479 use strict;
480 use warnings;
481 use base qw( Catalyst::Controller );
482 use MRO::Compat;
483 use mro 'c3';
484  
485 sub default : Path {
486 my (\$self, \$c) = \@_;
487 \$c->stash->{template} = '$base_path/default.tt';
488 }
489  
490 1;
491  
492 EOF
493 }
494  
495 0 ▶sub _make_controller {
Subroutine _make_controller: not called CC=1 SCAR=6.9
496 0 my ( $self, $rdbo_class, $form_class, $contr_class, $model_class ) = @_;
497 0 my $tmpl
498 = file( $self->_tmpl_path_from_controller($contr_class), 'edit.tt' );
499  
500 0 my $object_name
501 = $self->convention_manager->class_to_table_singular($rdbo_class);
502  
503 0 my $catalyst_prefix = $self->catalyst_prefix;
504 0 my $base_rdbo_class = $self->garden_prefix;
505  
506 # just the model short name is wanted.
507 # otherwise we get false partial matches.
508 0 $model_class =~ s/^${catalyst_prefix}::Model:://;
509  
510 0 my @pk = $rdbo_class->meta->primary_key_column_names;
511 0 my $pk = join( "', '", @pk );
512  
513 0 return <<EOF;
514 package $contr_class;
515 use strict;
516 use base qw( ${catalyst_prefix}::Base::Controller::RHTMLO );
517 use MRO::Compat;
518 use mro 'c3';
519 use $form_class;
520  
521 __PACKAGE__->config(
522 form_class => '$form_class',
523 init_form => 'init_with_${object_name}',
524 init_object => '${object_name}_from_form',
525 default_template => '$tmpl',
526 model_name => '$model_class',
527 primary_key => ['$pk'],
528 view_on_single_result => 1,
529 page_size => 50,
530 );
531  
532 1;
533
534 EOF
535  
536 }
537  
538 0 ▶sub _make_base_rhtmlo_controller {
Subroutine _make_base_rhtmlo_controller: not called CC=1 SCAR=6.9
539 0 my $self = shift;
540 0 my $catalyst_prefix = $self->catalyst_prefix;
541  
542 0 return <<EOF;
543 package ${catalyst_prefix}::Base::Controller::RHTMLO;
544 use strict;
545 use warnings;
546 use base qw( Rose::DBx::Garden::Catalyst::Controller );
547 use MRO::Compat;
548 use mro 'c3';
549  
550 __PACKAGE__->config(
551 default_view => 'RDGC',
552 fmt_to_view_map => {
553 html => "RDGC",
554 json => "RDGC",
555 xls => "Excel"
556 },
557 );
558  
559 1;
560  
561 EOF
562 }
563  
564 0 ▶sub _make_base_rdbo_model {
Subroutine _make_base_rdbo_model: not called CC=1 SCAR=6.9
565 0 my $self = shift;
566 0 my $catprefix = $self->catalyst_prefix;
567  
568 0 return <<EOF;
569 package ${catprefix}::Base::Model::RDBO;
570 use strict;
571 use warnings;
572 use base qw( CatalystX::CRUD::Model::RDBO );
573 use MRO::Compat;
574 use mro 'c3';
575  
576 1;
577  
578 EOF
579 }
580  
581 0 ▶sub _make_model {
Subroutine _make_model: not called CC=1 SCAR=6.9
582 0 my ( $self, $model_class, $rdbo_class ) = @_;
583 0 my $catprefix = $self->catalyst_prefix;
584  
585 0 return <<EOF;
586 package $model_class;
587 use strict;
588 use base qw( ${catprefix}::Base::Model::RDBO );
589 use MRO::Compat;
590 use mro 'c3';
591  
592 __PACKAGE__->config(
593 name => '$rdbo_class',
594 page_size => 50,
595 );
596  
597 1;
598  
599 EOF
600  
601 }
602  
603 0 ▶sub _make_view {
Subroutine _make_view: not called CC=1 SCAR=6.9
604 0 my ($self) = @_;
605 0 my $cat_class = $self->catalyst_prefix;
606  
607 0 return <<EOF;
608 package ${cat_class}::View::RDGC;
609 use strict;
610 use warnings;
611 use base qw( Rose::DBx::Garden::Catalyst::View );
612 use MRO::Compat;
613 use mro 'c3';
614  
615 1;
616  
617 EOF
618 }
619  
620 0 ▶sub _make_excel_view {
Subroutine _make_excel_view: not called CC=1 SCAR=6.9
621 0 my ($self) = @_;
622 0 my $cat_class = $self->catalyst_prefix;
623  
624 0 return <<EOF;
625 package ${cat_class}::View::Excel;
626 use strict;
627 use warnings;
628 use base qw( CatalystX::CRUD::View::Excel );
629 use CatalystX::CRUD::YUI;
630 use MRO::Compat;
631 use mro 'c3';
632  
633 sub get_template_params {
634 my ( \$self, \$c ) = \@_;
635 my \$cvar = \$self->config->{CATALYST_VAR} || 'c';
636 return (
637 \$cvar => \$c,
638 \%{ \$c->stash },
639 yui => CatalystX::CRUD::YUI->new,
640 );
641 }
642  
643 1;
644  
645 EOF
646 }
647  
648 2 1;
649  
650 __END__
651  
652 =head1 AUTHOR
653  
654 Peter Karman, C<< <karman at cpan.org> >>
655  
656 =head1 TODO
657  
658 =over
659  
660 =item client-side JS validation
661  
662 Should be straightforward since the Garden nows puts column-type as xhtml class value.
663  
664 =item RDGC tests
665  
666 Need a way to reliably test the JS.
667  
668 =back
669  
670 =head1 BUGS
671  
672 Known issues:
673  
674 =over
675  
676 =item re-running the script fails to pick up all classes
677  
678 This is due to issues with @INC and how the RDBO Loader requires classes.
679 There is no known workaround at the moment.
680  
681 =item javascript required
682  
683 The TT templates generated depend heavily on the YUI toolkit
684 C<< http://developer.yahoo.com/yui/ >>.
685 Graceful degredation is not implemented as yet.
686  
687 =back
688  
689 Please report any bugs or feature requests to
690 C<bug-rose-dbx-garden-catalyst at rt.cpan.org>, or through the web interface at
691 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rose-DBx-Garden-Catalyst>.
692 I will be notified, and then you'll automatically be notified of progress on
693 your bug as I make changes.
694  
695 =head1 SUPPORT
696  
697 You can find documentation for this module with the perldoc command.
698  
699 perldoc Rose::DBx::Garden::Catalyst
700  
701 You can also look for information at:
702  
703 =over 4
704  
705 =item * AnnoCPAN: Annotated CPAN documentation
706  
707 L<http://annocpan.org/dist/Rose-DBx-Garden-Catalyst>
708  
709 =item * CPAN Ratings
710  
711 L<http://cpanratings.perl.org/d/Rose-DBx-Garden-Catalyst>
712  
713 =item * RT: CPAN's request tracker
714  
715 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Rose-DBx-Garden-Catalyst>
716  
717 =item * Search CPAN
718  
719 L<http://search.cpan.org/dist/Rose-DBx-Garden-Catalyst>
720  
721 =back
722  
723 =head1 ACKNOWLEDGEMENTS
724  
725 The Minnesota Supercomputing Institute C<< http://www.msi.umn.edu/ >>
726 sponsored the development of this software.
727  
728 =head1 COPYRIGHT & LICENSE
729  
730 Copyright 2008 by the Regents of the University of Minnesota.
731  
732 This program is free software; you can redistribute it and/or modify it
733 under the same terms as Perl itself.
734  
735  
736 =cut
↑ Summary Catalyst/Controller.pm »