blib/lib/Catalyst/Helper/Controller/Scaffold/HTML/Template.pm

filter: Statementstmt 36.3% 8 / 22 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 39.2% 11 / 28 CC 3 SCAR 20.3
CC
3
Cov
33%
mk_compclass
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.6
↑ Summary
1 package Catalyst::Helper::Controller::Scaffold::HTML::Template;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.04';
7  
8 =head1 NAME
9  
10 Catalyst::Helper::Controller::Scaffold::HTML::Template - Helper for Scaffolding using HTML::Template.
11  
12 =head1 SYNOPSIS
13  
14 # Imagine you want to generate a scaffolding controller MyApp::C::SomeTable
15 # for a CDBI table class MyApp::M::CDBI::SomeTable
16 script/myapp_create.pl controller SomeTable Scaffold::HTML::Template CDBI::SomeTable
17  
18 =head1 DESCRIPTION
19  
20 This module is heavily based on Catalyst::Helper::Controller::Scaffold.
21 It provides a framework to do the basic data operations (edit, view, list,
22 delete, add).
23  
24 Scaffolding is very simple with Catalyst, as most of the code will be automagically
25 generated to handle the basic operations.
26  
27 Let's say you want to handle the data in SomeTable, all you have to do is :
28  
29 script/myapp_create.pl controller SomeTable Scaffold::HTML::Template CDBI::SomeTable
30  
31 this will create a controller for SomeTable using the model CDBI::SomeTable and
32 all the required HTML::Template, namely :
33  
34 lib/myapp/C/SomeTable.pm
35 root/SomeTable/add.tmpl
36 root/SomeTable/edit.tmpl
37 root/SomeTable/list.tmpl
38 root/SomeTable/view.tmpl
39  
40 Now just add these lines to your CDBI class...
41  
42 use Class::DBI::AsForm;
43 use Class::DBI::FromForm;
44  
45 ...and modify the one in your application class, to load the FormValidator plugin.
46  
47 use Catalyst qw/-Debug FormValidator/;
48  
49 You're done !
50  
51 Just browse http://127.0.0.1:3000/sometable and enjoy the Catalyst's power :
52 You can now add elements in SomeTable, view them, modify them, list them and delete them.
53
54 =head1 METHODS
55  
56 =over 4
57  
58 =item mk_compclass
59  
60 mk_compclass now accept a hashref as its last argument.
61 This hash can be used to overrides all $helper attributes
62 before calling its mk_dir and render_file methods
63  
64 =cut
65  
66 0 ▶sub mk_compclass {
Subroutine mk_compclass: not called CC=3 SCAR=24.8
Pod documented
67 0 my ( $self, $helper, $table_class, $ref_options ) = @_;
68 0 ▶ if ($ref_options) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_options) 0 0 0
69 0 my %options = %$ref_options;
70 0 for (keys %options) { $helper->{$_} = $options{$_} }
71 }
72 0 $helper->{table_class} = $helper->{app} . '::M::' . $table_class;
73 0 my $file = $helper->{file};
74 0 my $dir = dir( $helper->{base}, 'root', $helper->{prefix} );
75 0 $helper->mk_dir($dir);
76 0 $helper->render_file( 'compclass', $file );
77 0 $helper->render_file( 'add', file( $dir, 'add.tmpl' ) );
78 0 $helper->render_file( 'edit', file( $dir, 'edit.tmpl' ) );
79 0 $helper->render_file( 'list', file( $dir, 'list.tmpl' ) );
80 0 $helper->render_file( 'view', file( $dir, 'view.tmpl' ) );
81 }
82  
83 =back
84  
85 =head1 AUTHOR
86  
87 Sebastian Riedel, Arnaud Assad
88  
89 =head1 LICENSE
90  
91 This library is free software . You can redistribute it and/or modify
92 it under the same terms as perl itself.
93  
94 =cut
95  
96 2 1;
97  
98 __DATA__
↑ Summary