helpers now create .new files where files to be created already exist; -nonew option...
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
CommitLineData
fc7ec1d9 1package Catalyst;
2
3use strict;
5d9a6d47 4use base qw[ Catalyst::Base Catalyst::Setup ];
fc7ec1d9 5use UNIVERSAL::require;
a2f2cde9 6use Catalyst::Exception;
fc7ec1d9 7use Catalyst::Log;
812a28c9 8use Catalyst::Utils;
5d9a6d47 9use NEXT;
0f7ecc53 10use Text::ASCIITable;
4f6748f1 11use Path::Class;
367d15f8 12our $CATALYST_SCRIPT_GEN = 4;
fc7ec1d9 13
10dd6896 14__PACKAGE__->mk_classdata($_) for qw/arguments dispatcher engine log/;
15
62d9b030 16our $VERSION = '5.31';
fc7ec1d9 17our @ISA;
18
19=head1 NAME
20
21Catalyst - The Elegant MVC Web Application Framework
22
23=head1 SYNOPSIS
24
25 # use the helper to start a new application
91864987 26 catalyst.pl MyApp
fc7ec1d9 27 cd MyApp
28
29 # add models, views, controllers
ae4e40a7 30 script/myapp_create.pl model Something
31 script/myapp_create.pl view Stuff
32 script/myapp_create.pl controller Yada
fc7ec1d9 33
34 # built in testserver
ae4e40a7 35 script/myapp_server.pl
fc7ec1d9 36
37 # command line interface
ae4e40a7 38 script/myapp_test.pl /yada
fc7ec1d9 39
40
fc7ec1d9 41 use Catalyst;
42
43 use Catalyst qw/My::Module My::OtherModule/;
44
45 use Catalyst '-Debug';
46
47 use Catalyst qw/-Debug -Engine=CGI/;
48
5a8ed4fe 49 sub default : Private { $_[1]->res->output('Hello') } );
50
e3dc9d78 51 sub index : Path('/index.html') {
5a8ed4fe 52 my ( $self, $c ) = @_;
53 $c->res->output('Hello');
064834ea 54 $c->forward('foo');
5a8ed4fe 55 }
56
064834ea 57 sub product : Regex('^product[_]*(\d*).html$') {
5a8ed4fe 58 my ( $self, $c ) = @_;
59 $c->stash->{template} = 'product.tt';
60 $c->stash->{product} = $c->req->snippets->[0];
61 }
fc7ec1d9 62
3803e98f 63See also L<Catalyst::Manual::Intro>
64
fc7ec1d9 65=head1 DESCRIPTION
66
fc7ec1d9 67The key concept of Catalyst is DRY (Don't Repeat Yourself).
68
69See L<Catalyst::Manual> for more documentation.
70
23f9d934 71Catalyst plugins can be loaded by naming them as arguments to the "use Catalyst" statement.
1985c30b 72Omit the C<Catalyst::Plugin::> prefix from the plugin name,
23f9d934 73so C<Catalyst::Plugin::My::Module> becomes C<My::Module>.
fc7ec1d9 74
75 use Catalyst 'My::Module';
76
23f9d934 77Special flags like -Debug and -Engine can also be specifed as arguments when
78Catalyst is loaded:
fc7ec1d9 79
80 use Catalyst qw/-Debug My::Module/;
81
23f9d934 82The position of plugins and flags in the chain is important, because they are
83loaded in exactly the order that they appear.
fc7ec1d9 84
23f9d934 85The following flags are supported:
86
87=over 4
88
89=item -Debug
90
91enables debug output, i.e.:
fc7ec1d9 92
93 use Catalyst '-Debug';
94
23f9d934 95this is equivalent to:
fc7ec1d9 96
97 use Catalyst;
98 sub debug { 1 }
99
23f9d934 100=item -Engine
fc7ec1d9 101
102Force Catalyst to use a specific engine.
23f9d934 103Omit the C<Catalyst::Engine::> prefix of the engine name, i.e.:
fc7ec1d9 104
105 use Catalyst '-Engine=CGI';
106
23f9d934 107=back
fc7ec1d9 108
23f9d934 109=head1 METHODS
110
111=over 4
112
113=item debug
fc7ec1d9 114
115Overload to enable debug messages.
116
117=cut
118
119sub debug { 0 }
120
23f9d934 121=item config
fc7ec1d9 122
123Returns a hashref containing your applications settings.
124
125=cut
126
fc7ec1d9 127sub import {
0319a12c 128 my ( $class, @arguments ) = @_;
953b0e15 129
130 # We have to limit $class to Catalyst to avoid pushing Catalyst upon every
131 # callers @ISA.
599b5295 132 return unless $class eq 'Catalyst';
133
fc7ec1d9 134 my $caller = caller(0);
953b0e15 135
136 unless ( $caller->isa('Catalyst') ) {
fc7ec1d9 137 no strict 'refs';
0319a12c 138 push @{"$caller\::ISA"}, $class;
1c99e125 139 }
0319a12c 140
10dd6896 141 $caller->arguments( [ @arguments ] );
142 $caller->setup_home;
0319a12c 143}
144
145=item $c->engine
146
147Contains the engine class.
fc7ec1d9 148
0319a12c 149=item $c->log
150
151Contains the logging object. Unless it is already set Catalyst sets this up with a
152C<Catalyst::Log> object. To use your own log class:
153
154 $c->log( MyLogger->new );
155 $c->log->info("now logging with my own logger!");
156
157Your log class should implement the methods described in the C<Catalyst::Log>
158man page.
159
160=item $c->plugin( $name, $class, @args )
161
162Instant plugins for Catalyst.
163Classdata accessor/mutator will be created, class loaded and instantiated.
164
165 MyApp->plugin( 'prototype', 'HTML::Prototype' );
166
167 $c->prototype->define_javascript_functions;
168
169=cut
170
171sub plugin {
172 my ( $class, $name, $plugin, @args ) = @_;
173 $plugin->require;
174
175 if ( my $error = $UNIVERSAL::require::ERROR ) {
176 Catalyst::Exception->throw(
177 message => qq/Couldn't load instant plugin "$plugin", "$error"/
178 );
179 }
180
181 eval { $plugin->import };
182 $class->mk_classdata($name);
183 my $obj;
184 eval { $obj = $plugin->new(@args) };
185
186 if ( $@ ) {
187 Catalyst::Exception->throw(
188 message => qq/Couldn't instantiate instant plugin "$plugin", "$@"/
189 );
190 }
191
192 $class->$name($obj);
193 $class->log->debug(qq/Initialized instant plugin "$plugin" as "$name"/)
194 if $class->debug;
195}
196
23f9d934 197=back
198
d2ee9760 199=head1 CASE SENSITIVITY
200
201By default Catalyst is not case sensitive, so C<MyApp::C::FOO::Bar> becomes
202C</foo/bar>.
203
204But you can activate case sensitivity with a config parameter.
205
206 MyApp->config->{case_sensitive} = 1;
207
d1a31ac6 208=head1 LIMITATIONS
209
b2b7d352 210mod_perl2 support is considered experimental and may contain bugs.
d1a31ac6 211
3cb1db8c 212=head1 SUPPORT
213
214IRC:
215
216 Join #catalyst on irc.perl.org.
217
218Mailing-Lists:
219
220 http://lists.rawmode.org/mailman/listinfo/catalyst
221 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
1985c30b 222
432d507d 223Web:
224
225 http://catalyst.perl.org
226
fc7ec1d9 227=head1 SEE ALSO
228
61b1e958 229=over 4
230
231=item L<Catalyst::Manual> - The Catalyst Manual
232
233=item L<Catalyst::Engine> - Core Engine
234
235=item L<Catalyst::Log> - The Log Class.
236
237=item L<Catalyst::Request> - The Request Object
238
239=item L<Catalyst::Response> - The Response Object
240
241=item L<Catalyst::Test> - The test suite.
242
243=back
fc7ec1d9 244
15f0b5b7 245=head1 CREDITS
fc7ec1d9 246
15f0b5b7 247Andy Grundman
248
249Andrew Ford
250
251Andrew Ruthven
252
253Autrijus Tang
254
255Christian Hansen
256
257Christopher Hicks
258
259Dan Sully
260
261Danijel Milicevic
262
263David Naughton
264
265Gary Ashton Jones
266
267Geoff Richards
268
269Jesse Sheidlower
270
271Jody Belka
272
273Johan Lindstrom
274
275Juan Camacho
276
277Leon Brocard
278
279Marcus Ramberg
280
281Matt S Trout
282
51f0308d 283Sebastian Riedel
284
15f0b5b7 285Tatsuhiko Miyagawa
fc7ec1d9 286
51f0308d 287Ulf Edvinsson
288
289=head1 AUTHOR
290
291Sebastian Riedel, C<sri@oook.de>
292
fc7ec1d9 293=head1 LICENSE
294
295This library is free software . You can redistribute it and/or modify it under
296the same terms as perl itself.
297
298=cut
299
3001;