File Coverage

blib/lib/Mojolicious.pm
Criterion Covered Total %
statement 136 140 97.1
branch 25 28 89.2
condition 18 24 75.0
subroutine 112 113 99.1
pod 14 15 93.3
total 305 320 95.3


line stmt bran cond sub pod time code
1             package Mojolicious;
2 54     54   200104 use Mojo::Base -base;
  54         126  
  54         485  
3              
4             # "Fry: Shut up and take my money!"
5 54     54   469 use Carp ();
  54         2754  
  54         2886  
6 54     54   41118 use Mojo::DynamicMethods -dispatch;
  54         194  
  54         460  
7 54     54   6459 use Mojo::Exception;
  54         1409  
  54         3399  
8 54     54   29071 use Mojo::Home;
  54         194  
  54         3597  
9 54     54   6340 use Mojo::Loader;
  54         153  
  54         2412  
10 54     54   30408 use Mojo::Log;
  54         245  
  54         670  
11 54     54   7770 use Mojo::Server;
  54         179  
  54         599  
12 54     54   317 use Mojo::Util;
  54         154  
  54         2664  
13 54     54   12363 use Mojo::UserAgent;
  54         161  
  54         573  
14 54     54   36672 use Mojolicious::Commands;
  54         262  
  54         733  
15 54     54   36492 use Mojolicious::Controller;
  54         263  
  54         533  
16 54     54   36910 use Mojolicious::Plugins;
  54         204  
  54         533  
17 54     54   32891 use Mojolicious::Renderer;
  54         288  
  54         542  
18 54     54   35364 use Mojolicious::Routes;
  54         321  
  54         650  
19 54     54   36895 use Mojolicious::Sessions;
  54         238  
  54         509  
20 54     54   34036 use Mojolicious::Static;
  54         281  
  54         1012  
21 54     54   35138 use Mojolicious::Types;
  54         256  
  54         765  
22 54     54   31480 use Mojolicious::Validator;
  54         228  
  54         760  
23 54     54   456 use Scalar::Util ();
  54         128  
  54         181667  
24              
25             has commands => sub { Mojolicious::Commands->new(app => shift) };
26             has controller_class => 'Mojolicious::Controller';
27             has exception_format => 'html';
28             has home => sub { Mojo::Home->new->detect(ref shift) };
29             has log => sub {
30             my $self = shift;
31              
32             # Reduced log output outside of development mode
33             my $log = Mojo::Log->new;
34             return $log->level($ENV{MOJO_LOG_LEVEL}) if $ENV{MOJO_LOG_LEVEL};
35             return $self->mode eq 'development' ? $log : $log->level('info');
36             };
37             has 'max_request_size';
38             has mode => sub { $ENV{MOJO_MODE} || $ENV{PLACK_ENV} || 'development' };
39             has moniker => sub { Mojo::Util::decamelize ref shift };
40             has plugins => sub { Mojolicious::Plugins->new };
41             has preload_namespaces => sub { [] };
42             has renderer => sub { Mojolicious::Renderer->new };
43             has routes => sub { Mojolicious::Routes->new };
44             has secrets => sub {
45             my $self = shift;
46              
47             # Warn developers about insecure default
48             $self->log->trace('Your secret passphrase needs to be changed (see FAQ for more)');
49              
50             # Default to moniker
51             return [$self->moniker];
52             };
53             has sessions => sub { Mojolicious::Sessions->new };
54             has static => sub { Mojolicious::Static->new };
55             has types => sub { Mojolicious::Types->new };
56             has ua => sub { Mojo::UserAgent->new };
57             has validator => sub { Mojolicious::Validator->new };
58              
59             our $CODENAME = 'Waffle';
60             our $VERSION = '9.42';
61              
62             sub BUILD_DYNAMIC {
63 3661     3661 0 7799 my ($class, $method, $dyn_methods) = @_;
64              
65             return sub {
66 57     57   151 my $self = shift;
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        72      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        58      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        68      
        68      
        68      
        68      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        16      
67 57         276 my $dynamic = $dyn_methods->{$self->renderer}{$method};
68 57 50       326 return $self->build_controller->$dynamic(@_) if $dynamic;
69 0         0 my $package = ref $self;
70 0         0 Carp::croak qq{Can't locate object method "$method" via package "$package"};
71 3661         27909 };
72             }
73              
74             sub build_controller {
75 1193     1193 1 4612 my ($self, $tx) = @_;
76              
77             # Embedded application
78 1193         2485 my $stash = {};
79 1193 100 100     10075 if ($tx && (my $sub = $tx->can('stash'))) { ($stash, $tx) = ($tx->$sub, $tx->tx) }
  71         219  
80              
81             # Build default controller
82 1193         4635 my $defaults = $self->defaults;
83 1193         5607 @$stash{keys %$defaults} = values %$defaults;
84 1193         6512 my $c = $self->controller_class->new(app => $self, stash => $stash, tx => $tx);
85 1193   66     4885 $c->{tx} ||= $self->build_tx;
86              
87 1193         3596 return $c;
88             }
89              
90             sub build_tx {
91 1123     1123 1 2689 my $self = shift;
92              
93 1123         6854 my $tx = Mojo::Transaction::HTTP->new;
94 1123         6062 my $max = $self->max_request_size;
95 1123 100       3489 $tx->req->max_message_size($max) if defined $max;
96 1123         4476 $self->plugins->emit_hook(after_build_tx => $tx, $self);
97              
98 1123         3031 return $tx;
99             }
100              
101 239     239 1 962 sub config { Mojo::Util::_stash(config => @_) }
102 1232     1232 1 6415 sub defaults { Mojo::Util::_stash(defaults => @_) }
103              
104             sub dispatch {
105 1100     1100 1 2910 my ($self, $c) = @_;
106              
107 1100         6977 my $plugins = $self->plugins->emit_hook(before_dispatch => $c);
108              
109 1100         5868 my $stash = $c->stash;
110 1100 100       3710 return if $stash->{'mojo.rendered'};
111              
112             # Try to find a static file
113 1093         4203 my $tx = $c->tx;
114 1093 50 66     4273 $self->static->dispatch($c) and $plugins->emit_hook(after_static => $c) unless $tx->res->code;
115              
116             # Start timer (ignore static files)
117             $c->helpers->log->trace(sub {
118 280     280   1293 my $req = $c->req;
119 280         914 my $method = $req->method;
120 280         1072 my $path = $req->url->path->to_abs_string;
121 280         1373 $c->helpers->timing->begin('mojo.timer');
122 280         1861 return qq{$method "$path"};
123 1093 100       8217 }) unless $stash->{'mojo.static'};
124              
125             # Routes
126 1093         11429 $plugins->emit_hook(before_routes => $c);
127 1093 100 100     4397 $c->helpers->reply->not_found unless $tx->res->code || $self->routes->dispatch($c) || $tx->res->code;
      100        
128             }
129              
130             sub handler {
131 1101     1101 1 2637 my $self = shift;
132              
133             # Dispatcher has to be last in the chain
134             ++$self->{dispatch}
135             and $self->hook(around_action => \&_action)
136 1100     1100   5506 and $self->hook(around_dispatch => sub { $_[1]->app->dispatch($_[1]) })
137 1101 100 33     5011 unless $self->{dispatch};
      33        
138              
139             # Process with chain
140 1101         6575 my $c = $self->build_controller(@_);
141 1101         4274 $self->plugins->emit_chain(around_dispatch => $c);
142              
143             # Delayed response
144             $c->helpers->log->trace('Nothing has been rendered, expecting delayed response (see FAQ for more)')
145 1101 100       4393 unless $c->stash->{'mojo.rendered'};
146             }
147              
148 9534     9534 1 29150 sub helper { shift->renderer->add_helper(@_) }
149              
150 283     283 1 1119 sub hook { shift->plugins->on(@_) }
151              
152             sub new {
153 109 50   109 1 114114 my $self = shift->SUPER::new((ref $_[0] ? %{shift()} : @_), @Mojo::Server::ARGS_OVERRIDE);
  0         0  
154              
155 109         652 my $home = $self->home;
156 109         272 push @{$self->renderer->paths}, $home->child('templates')->to_string;
  109         754  
157 109         670 push @{$self->static->paths}, $home->child('public')->to_string;
  109         625  
158              
159             # Default to controller and application namespace
160 109         318 my $controller = "@{[ref $self]}::Controller";
  109         520  
161 109         989 my $r = $self->preload_namespaces([$controller])->routes->namespaces([$controller, ref $self]);
162              
163 109         804 $self->plugin($_) for qw(HeaderCondition DefaultHelpers TagHelpers EPLRenderer EPRenderer);
164              
165             # Exception handling should be first in chain
166 109         1061 $self->hook(around_dispatch => \&_exception);
167              
168 109         859 $self->startup;
169 109         775 $self->warmup;
170              
171 109         761 return $self;
172             }
173              
174             sub plugin {
175 629     629 1 1516 my $self = shift;
176 629         2414 $self->plugins->register_plugin(shift, $self, @_);
177             }
178              
179 189     189 1 800 sub server { $_[0]->plugins->emit_hook(before_server_start => @_[1, 0]) }
180              
181             sub start {
182 29     29 1 5369 my $self = shift;
183 29         132 $_->warmup for $self->static, $self->renderer;
184 29 100       178 return $self->commands->run(@_ ? @_ : @ARGV);
185             }
186              
187       73 1   sub startup { }
188              
189 109     109 1 294 sub warmup { Mojo::Loader::load_classes $_ for @{shift->preload_namespaces} }
  109         724  
190              
191             sub _action {
192 668     668   2058 my ($next, $c, $action, $last) = @_;
193 668         3444 my $val = $action->($c);
194 638 100 100 0   8828 $val->catch(sub { $c->helpers->reply->exception(shift) }) if Scalar::Util::blessed $val && $val->isa('Mojo::Promise');
  0         0  
195 638         5973 return $val;
196             }
197              
198 135 100   135   3061 sub _die { CORE::die ref $_[0] ? $_[0] : Mojo::Exception->new(shift)->trace }
199              
200             sub _exception {
201 1101     1101   3069 my ($next, $c) = @_;
202 1101         8441 local $SIG{__DIE__} = \&_die;
203 1101 100       2556 $c->helpers->reply->exception($@) unless eval { $next->(); 1 };
  1101         3465  
  1041         12550  
204             }
205              
206             1;
207              
208             =encoding utf8
209              
210             =head1 NAME
211              
212             Mojolicious - Real-time web framework
213              
214             =head1 SYNOPSIS
215              
216             # Application
217             package MyApp;
218             use Mojo::Base 'Mojolicious', -signatures;
219              
220             # Route
221             sub startup ($self) {
222             $self->routes->get('/hello')->to('foo#hello');
223             }
224              
225             # Controller
226             package MyApp::Controller::Foo;
227             use Mojo::Base 'Mojolicious::Controller', -signatures;
228              
229             # Action
230             sub hello ($self) {
231             $self->render(text => 'Hello World!');
232             }
233              
234             =head1 DESCRIPTION
235              
236             An amazing real-time web framework built on top of the powerful L web development toolkit. With support for
237             RESTful routes, plugins, commands, Perl-ish templates, content negotiation, session management, form validation,
238             testing framework, static file server, C/C detection, first class Unicode support and much more for you to
239             discover.
240              
241             Take a look at our excellent documentation in L!
242              
243             =head1 HOOKS
244              
245             L will emit the following hooks in the listed order.
246              
247             =head2 before_command
248              
249             Emitted right before the application runs a command through the command line interface.
250              
251             $app->hook(before_command => sub ($command, $args) {...});
252              
253             Useful for reconfiguring the application before running a command or to modify the behavior of a command. (Passed the
254             command object and the command arguments)
255              
256             =head2 before_server_start
257              
258             Emitted right before the application server is started, for web servers that support it, which includes all the
259             built-in ones.
260              
261             $app->hook(before_server_start => sub ($server, $app) {...});
262              
263             Useful for reconfiguring application servers dynamically or collecting server diagnostics information. (Passed the
264             server and application objects)
265              
266             =head2 after_build_tx
267              
268             Emitted right after the transaction is built and before the HTTP request gets parsed.
269              
270             $app->hook(after_build_tx => sub ($tx, $app) {...});
271              
272             This is a very powerful hook and should not be used lightly, it makes some rather advanced features such as upload
273             progress bars possible. Note that this hook will not work for embedded applications, because only the host application
274             gets to build transactions. (Passed the transaction and application objects)
275              
276             =head2 around_dispatch
277              
278             Emitted right after a new request has been received and wraps around the whole dispatch process, so you have to
279             manually forward to the next hook if you want to continue the chain. Default exception handling with
280             Lexception"> is the first hook in the chain and a call to
281             L the last, yours will be in between.
282              
283             $app->hook(around_dispatch => sub ($next, $c) {
284             ...
285             $next->();
286             ...
287             });
288              
289             This is a very powerful hook and should not be used lightly, it allows you to, for example, customize application-wide
290             exception handling, consider it the sledgehammer in your toolbox. (Passed a callback leading to the next hook and the
291             default controller object)
292              
293             =head2 before_dispatch
294              
295             Emitted right before the static file server and router start their work.
296              
297             $app->hook(before_dispatch => sub ($c) {...});
298              
299             Very useful for rewriting incoming requests and other preprocessing tasks. (Passed the default controller object)
300              
301             =head2 after_static
302              
303             Emitted after a static file response has been generated by the static file server.
304              
305             $app->hook(after_static => sub ($c) {...});
306              
307             Mostly used for post-processing static file responses. (Passed the default controller object)
308              
309             =head2 before_routes
310              
311             Emitted after the static file server determined if a static file should be served and before the router starts its
312             work.
313              
314             $app->hook(before_routes => sub ($c) {...});
315              
316             Mostly used for custom dispatchers and collecting metrics. (Passed the default controller object)
317              
318             =head2 around_action
319              
320             Emitted right before an action gets executed and wraps around it, so you have to manually forward to the next hook if
321             you want to continue the chain. Default action dispatching is the last hook in the chain, yours will run before it.
322              
323             $app->hook(around_action => sub ($next, $c, $action, $last) {
324             ...
325             return $next->();
326             });
327              
328             This is a very powerful hook and should not be used lightly, it allows you for example to pass additional arguments to
329             actions or handle return values differently. Note that this hook can trigger more than once for the same request if
330             there are nested routes. (Passed a callback leading to the next hook, the current controller object, the action
331             callback and a flag indicating if this action is an endpoint)
332              
333             =head2 before_render
334              
335             Emitted before content is generated by the renderer. Note that this hook can trigger out of order due to its dynamic
336             nature, and with embedded applications will only work for the application that is rendering.
337              
338             $app->hook(before_render => sub ($c, $args) {...});
339              
340             Mostly used for pre-processing arguments passed to the renderer. (Passed the current controller object and the render
341             arguments)
342              
343             =head2 after_render
344              
345             Emitted after content has been generated by the renderer that will be assigned to the response. Note that this hook can
346             trigger out of order due to its dynamic nature, and with embedded applications will only work for the application that
347             is rendering.
348              
349             $app->hook(after_render => sub ($c, $output, $format) {...});
350              
351             Mostly used for post-processing dynamically generated content. (Passed the current controller object, a reference to
352             the content and the format)
353              
354             =head2 after_dispatch
355              
356             Emitted in reverse order after a response has been generated. Note that this hook can trigger out of order due to its
357             dynamic nature, and with embedded applications will only work for the application that is generating the response.
358              
359             $app->hook(after_dispatch => sub ($c) {...});
360              
361             Useful for rewriting outgoing responses and other post-processing tasks. (Passed the current controller object)
362              
363             =head1 ATTRIBUTES
364              
365             L implements the following attributes.
366              
367             =head2 commands
368              
369             my $commands = $app->commands;
370             $app = $app->commands(Mojolicious::Commands->new);
371              
372             Command line interface for your application, defaults to a L object.
373              
374             # Add another namespace to load commands from
375             push @{$app->commands->namespaces}, 'MyApp::Command';
376              
377             =head2 controller_class
378              
379             my $class = $app->controller_class;
380             $app = $app->controller_class('Mojolicious::Controller');
381              
382             Class to be used for the default controller, defaults to L. Note that this class needs to have
383             already been loaded before the first request arrives.
384              
385             =head2 exception_format
386              
387             my $format = $app->exception_format;
388             $app = $app->exception_format('txt');
389              
390             Format for HTTP exceptions (C, C, or C), defaults to C.
391              
392             =head2 home
393              
394             my $home = $app->home;
395             $app = $app->home(Mojo::Home->new);
396              
397             The home directory of your application, defaults to a L object which stringifies to the actual path.
398              
399             # Portably generate path relative to home directory
400             my $path = $app->home->child('data', 'important.txt');
401              
402             =head2 log
403              
404             my $log = $app->log;
405             $app = $app->log(Mojo::Log->new);
406              
407             The logging layer of your application, defaults to a L object. The level will default to either the
408             C environment variable, C if the L is C, or C otherwise. All messages
409             will be written to C by default.
410              
411             # Log debug message
412             $app->log->debug('It works');
413              
414             =head2 max_request_size
415              
416             my $max = $app->max_request_size;
417             $app = $app->max_request_size(16777216);
418              
419             Maximum request size in bytes, defaults to the value of L. Setting the value to C<0>
420             will allow requests of indefinite size. Note that increasing this value can also drastically increase memory usage,
421             should you for example attempt to parse an excessively large request body with the methods L or
422             L.
423              
424             =head2 mode
425              
426             my $mode = $app->mode;
427             $app = $app->mode('production');
428              
429             The operating mode for your application, defaults to a value from the C and C environment
430             variables or C.
431              
432             =head2 moniker
433              
434             my $moniker = $app->moniker;
435             $app = $app->moniker('foo_bar');
436              
437             Moniker of this application, often used as default filename for configuration files and the like, defaults to
438             decamelizing the application class with L.
439              
440             =head2 plugins
441              
442             my $plugins = $app->plugins;
443             $app = $app->plugins(Mojolicious::Plugins->new);
444              
445             The plugin manager, defaults to a L object. See the L method below if you want to load
446             a plugin.
447              
448             # Add another namespace to load plugins from
449             push @{$app->plugins->namespaces}, 'MyApp::Plugin';
450              
451             =head2 preload_namespaces
452              
453             my $namespaces = $app->preload_namespaces;
454             $app = $app->preload_namespaces(['MyApp::Controller']);
455              
456             Namespaces to preload classes from during application startup.
457              
458             =head2 renderer
459              
460             my $renderer = $app->renderer;
461             $app = $app->renderer(Mojolicious::Renderer->new);
462              
463             Used to render content, defaults to a L object. For more information about how to generate
464             content see L.
465              
466             # Enable compression
467             $app->renderer->compress(1);
468              
469             # Add another "templates" directory
470             push @{$app->renderer->paths}, '/home/sri/templates';
471              
472             # Add another "templates" directory with higher precedence
473             unshift @{$app->renderer->paths}, '/home/sri/themes/blue/templates';
474              
475             # Add another class with templates in DATA section
476             push @{$app->renderer->classes}, 'Mojolicious::Plugin::Fun';
477              
478             =head2 routes
479              
480             my $routes = $app->routes;
481             $app = $app->routes(Mojolicious::Routes->new);
482              
483             The router, defaults to a L object. You use this in your startup method to define the url
484             endpoints for your application.
485              
486             # Add routes
487             my $r = $app->routes;
488             $r->get('/foo/bar')->to('test#foo', title => 'Hello Mojo!');
489             $r->post('/baz')->to('test#baz');
490              
491             # Add another namespace to load controllers from
492             push @{$app->routes->namespaces}, 'MyApp::MyController';
493              
494             =head2 secrets
495              
496             my $secrets = $app->secrets;
497             $app = $app->secrets([$bytes]);
498              
499             Secret passphrases used for signed cookies and the like, defaults to the L of this application, which is
500             not very secure, so you should change it!!! As long as you are using the insecure default there will be debug messages
501             in the log file reminding you to change your passphrase. Only the first passphrase is used to create new signatures,
502             but all of them for verification. So you can increase security without invalidating all your existing signed cookies by
503             rotating passphrases, just add new ones to the front and remove old ones from the back.
504              
505             # Rotate passphrases
506             $app->secrets(['new_passw0rd', 'old_passw0rd', 'very_old_passw0rd']);
507              
508             =head2 sessions
509              
510             my $sessions = $app->sessions;
511             $app = $app->sessions(Mojolicious::Sessions->new);
512              
513             Signed cookie based session manager, defaults to a L object. You can usually leave this alone,
514             see L for more information about working with session data.
515              
516             # Enable encrypted sessions
517             $app->sessions->encrypted(1);
518              
519             # Change name of cookie used for all sessions
520             $app->sessions->cookie_name('mysession');
521              
522             # Disable SameSite feature
523             $app->sessions->samesite(undef);
524              
525             =head2 static
526              
527             my $static = $app->static;
528             $app = $app->static(Mojolicious::Static->new);
529              
530             For serving static files from your C directories, defaults to a L object.
531              
532             # Serve static files only with a "/static" prefix
533             $app->static->prefix('/static');
534              
535             # Add another "public" directory
536             push @{$app->static->paths}, '/home/sri/public';
537              
538             # Add another "public" directory with higher precedence
539             unshift @{$app->static->paths}, '/home/sri/themes/blue/public';
540              
541             # Add another class with static files in DATA section
542             push @{$app->static->classes}, 'Mojolicious::Plugin::Fun';
543              
544             # Remove built-in favicon
545             delete $app->static->extra->{'favicon.ico'};
546              
547             =head2 types
548              
549             my $types = $app->types;
550             $app = $app->types(Mojolicious::Types->new);
551              
552             Responsible for connecting file extensions with MIME types, defaults to a L object.
553              
554             # Add custom MIME type
555             $app->types->type(twt => 'text/tweet');
556              
557             =head2 ua
558              
559             my $ua = $app->ua;
560             $app = $app->ua(Mojo::UserAgent->new);
561              
562             A full featured HTTP user agent for use in your applications, defaults to a L object.
563              
564             # Perform blocking request
565             say $app->ua->get('example.com')->result->body;
566              
567             =head2 validator
568              
569             my $validator = $app->validator;
570             $app = $app->validator(Mojolicious::Validator->new);
571              
572             Validate values, defaults to a L object.
573              
574             # Add validation check
575             $app->validator->add_check(foo => sub ($v, $name, $value) {
576             return $value ne 'foo';
577             });
578              
579             # Add validation filter
580             $app->validator->add_filter(quotemeta => sub ($v, $name, $value) {
581             return quotemeta $value;
582             });
583              
584             =head1 METHODS
585              
586             L inherits all methods from L and implements the following new ones.
587              
588             =head2 build_controller
589              
590             my $c = $app->build_controller;
591             my $c = $app->build_controller(Mojo::Transaction::HTTP->new);
592             my $c = $app->build_controller(Mojolicious::Controller->new);
593              
594             Build default controller object with L.
595              
596             # Render template from application
597             my $foo = $app->build_controller->render_to_string(template => 'foo');
598              
599             =head2 build_tx
600              
601             my $tx = $app->build_tx;
602              
603             Build L object and emit L hook.
604              
605             =head2 config
606              
607             my $hash = $app->config;
608             my $foo = $app->config('foo');
609             $app = $app->config({foo => 'bar', baz => 23});
610             $app = $app->config(foo => 'bar', baz => 23);
611              
612             Application configuration.
613              
614             # Remove value
615             my $foo = delete $app->config->{foo};
616              
617             # Assign multiple values at once
618             $app->config(foo => 'test', bar => 23);
619              
620             =head2 defaults
621              
622             my $hash = $app->defaults;
623             my $foo = $app->defaults('foo');
624             $app = $app->defaults({foo => 'bar', baz => 23});
625             $app = $app->defaults(foo => 'bar', baz => 23);
626              
627             Default values for L, assigned for every new request.
628              
629             # Remove value
630             my $foo = delete $app->defaults->{foo};
631              
632             # Assign multiple values at once
633             $app->defaults(foo => 'test', bar => 23);
634              
635             =head2 dispatch
636              
637             $app->dispatch(Mojolicious::Controller->new);
638              
639             The heart of every L application, calls the L and L dispatchers for every request
640             and passes them a L object.
641              
642             =head2 handler
643              
644             $app->handler(Mojo::Transaction::HTTP->new);
645             $app->handler(Mojolicious::Controller->new);
646              
647             Sets up the default controller and emits the L hook for every request.
648              
649             =head2 helper
650              
651             $app->helper(foo => sub {...});
652              
653             Add or replace a helper that will be available as a method of the controller object and the application object, as well
654             as a function in C templates. For a full list of helpers that are available by default see
655             L and L.
656              
657             # Helper
658             $app->helper(cache => sub { state $cache = {} });
659              
660             # Application
661             $app->cache->{foo} = 'bar';
662             my $result = $app->cache->{foo};
663              
664             # Controller
665             $c->cache->{foo} = 'bar';
666             my $result = $c->cache->{foo};
667              
668             # Template
669             % cache->{foo} = 'bar';
670             %= cache->{foo}
671              
672             =head2 hook
673              
674             $app->hook(after_dispatch => sub {...});
675              
676             Extend L with hooks, which allow code to be shared with all requests indiscriminately, for a full list of
677             available hooks see L.
678              
679             # Dispatchers will not run if there's already a response code defined
680             $app->hook(before_dispatch => sub ($c) {
681             $c->render(text => 'Skipped static file server and router!')
682             if $c->req->url->path->to_route =~ /do_not_dispatch/;
683             });
684              
685             =head2 new
686              
687             my $app = Mojolicious->new;
688             my $app = Mojolicious->new(moniker => 'foo_bar');
689             my $app = Mojolicious->new({moniker => 'foo_bar'});
690              
691             Construct a new L application and call L. Will automatically detect your home directory. Also
692             sets up the renderer, static file server, a default set of plugins and an L hook with the default
693             exception handling.
694              
695             =head2 plugin
696              
697             $app->plugin('some_thing');
698             $app->plugin('some_thing', foo => 23);
699             $app->plugin('some_thing', {foo => 23});
700             $app->plugin('SomeThing');
701             $app->plugin('SomeThing', foo => 23);
702             $app->plugin('SomeThing', {foo => 23});
703             $app->plugin('MyApp::Plugin::SomeThing');
704             $app->plugin('MyApp::Plugin::SomeThing', foo => 23);
705             $app->plugin('MyApp::Plugin::SomeThing', {foo => 23});
706              
707             Load a plugin, for a full list of example plugins included in the L distribution see
708             L.
709              
710             =head2 server
711              
712             $app->server(Mojo::Server->new);
713              
714             Emits the L hook.
715              
716             =head2 start
717              
718             $app->start;
719             $app->start(@ARGV);
720              
721             Start the command line interface for your application. For a full list of commands that are available by default see
722             L. Note that the options C<-h>/C<--help>, C<--home> and C<-m>/C<--mode>, which are
723             shared by all commands, will be parsed from C<@ARGV> during compile time.
724              
725             # Always start daemon
726             $app->start('daemon', '-l', 'http://*:8080');
727              
728             =head2 startup
729              
730             $app->startup;
731              
732             This is your main hook into the application, it will be called at application startup. Meant to be overloaded in a
733             subclass.
734              
735             sub startup ($self) {...}
736              
737             =head2 warmup
738              
739             $app->warmup;
740              
741             Preload classes from L for future use.
742              
743             =head1 HELPERS
744              
745             In addition to the L and L above you can also call helpers on L objects. This
746             includes all helpers from L and L. Note that
747             application helpers are always called with a new default controller object, so they can't depend on or change
748             controller state, which includes request, response and stash.
749              
750             # Call helper
751             say $app->dumper({foo => 'bar'});
752              
753             # Longer version
754             say $app->build_controller->helpers->dumper({foo => 'bar'});
755              
756             =head1 BUNDLED FILES
757              
758             The L distribution includes a few files with different licenses that have been bundled for internal use.
759              
760             =head2 Mojolicious Artwork
761              
762             Copyright (C) 2010-2025, Sebastian Riedel.
763              
764             Licensed under the CC-SA License, Version 4.0 L.
765              
766             =head2 highlight.js
767              
768             Copyright (C) 2006, Ivan Sagalaev.
769              
770             Licensed under the BSD License, L.
771              
772             =head2 Bootstrap
773              
774             Copyright 2011-2020 The Bootstrap Authors.
775             Copyright 2011-2020 Twitter, Inc.
776              
777             Licensed under the MIT License, L.
778              
779             =head2 Font Awesome
780              
781             Licensed under the CC-BY License, Version 4.0 L and SIL OFL, Version 1.1
782             L.
783              
784             =head1 CODE NAMES
785              
786             Every major release of L has a code name, these are the ones that have been used in the past.
787              
788             9.0, C (U+1F9C7)
789              
790             8.0, C (U+1F9B9)
791              
792             7.0, C (U+1F369)
793              
794             6.0, C (U+1F37B)
795              
796             5.0, C (U+1F42F)
797              
798             4.0, C (U+1F3A9)
799              
800             3.0, C (U+1F308)
801              
802             2.0, C (U+1F343)
803              
804             1.0, C (U+2744)
805              
806             =head1 SPONSORS
807              
808             =over 2
809              
810             =item
811              
812             L sponsored the creation of the Mojolicious logo (designed by Nicolai Graesdal) and transferred
813             its copyright to Sebastian Riedel.
814              
815             =item
816              
817             Some of the work on this distribution has been sponsored by L.
818              
819             =back
820              
821             =head1 AUTHORS
822              
823             L is an open source project that relies on the tireless support of its contributors.
824              
825             =head2 Project Founder
826              
827             Sebastian Riedel, C
828              
829             =head2 Core Developers
830              
831             Current voting members of the core team in alphabetical order:
832              
833             =over 2
834              
835             CandyAngel, C
836              
837             Christopher Rasch-Olsen Raa, C
838              
839             Dan Book, C
840              
841             Jan Henning Thorsen, C
842              
843             Joel Berger, C
844              
845             Marcus Ramberg, C
846              
847             =back
848              
849             The following members of the core team are currently on hiatus:
850              
851             =over 2
852              
853             Abhijit Menon-Sen, C
854              
855             Glen Hinkle, C
856              
857             =back
858              
859             =head2 Contributors
860              
861             In alphabetical order:
862              
863             =over 2
864              
865             Adam Kennedy
866              
867             Adriano Ferreira
868              
869             Al Newkirk
870              
871             Alex Efros
872              
873             Alex Salimon
874              
875             Alexander Karelas
876              
877             Alexander Kuehne
878              
879             Alexey Likhatskiy
880              
881             Anatoly Sharifulin
882              
883             Andre Parker
884              
885             Andre Vieth
886              
887             Andreas Guldstrand
888              
889             Andreas Jaekel
890              
891             Andreas Koenig
892              
893             Andrew Fresh
894              
895             Andrew Nugged
896              
897             Andrey Khozov
898              
899             Andrey Kuzmin
900              
901             Andy Grundman
902              
903             Andy Lester
904              
905             Aristotle Pagaltzis
906              
907             Ashley Dev
908              
909             Ask Bjoern Hansen
910              
911             Audrey Tang
912              
913             Ben Tyler
914              
915             Ben van Staveren
916              
917             Benjamin Erhart
918              
919             Bernhard Graf
920              
921             Breno G. de Oliveira
922              
923             Brett Watson
924              
925             Brian Duggan
926              
927             Brian Medley
928              
929             Burak Gursoy
930              
931             Ch Lamprecht
932              
933             Charlie Brady
934              
935             Chas. J. Owens IV
936              
937             Chase Whitener
938              
939             Chris Scheller
940              
941             Christian Hansen
942              
943             chromatic
944              
945             Curt Tilmes
946              
947             Daniel Kimsey
948              
949             Daniel Mantovani
950              
951             Danijel Tasov
952              
953             Dagfinn Ilmari Manns�ker
954              
955             Danny Thomas
956              
957             David Davis
958              
959             David Webb
960              
961             Diego Kuperman
962              
963             Dmitriy Shalashov
964              
965             Dmitry Konstantinov
966              
967             Dominik Jarmulowicz
968              
969             Dominique Dumont
970              
971             Dotan Dimet
972              
973             Douglas Christopher Wilson
974              
975             Elmar S. Heeb
976              
977             Ettore Di Giacinto
978              
979             Eugen Konkov
980              
981             Eugene Toropov
982              
983             Flavio Poletti
984              
985             Gisle Aas
986              
987             Graham Barr
988              
989             Graham Knop
990              
991             Heiko Jansen
992              
993             Henry Tang
994              
995             Hernan Lopes
996              
997             Hideki Yamamura
998              
999             Hiroki Toyokawa
1000              
1001             Ian Goodacre
1002              
1003             Ilya Chesnokov
1004              
1005             Ilya Rassadin
1006              
1007             James Duncan
1008              
1009             Jan Jona Javorsek
1010              
1011             Jan Schmidt
1012              
1013             Jaroslav Muhin
1014              
1015             Jesse Vincent
1016              
1017             Johannes Plunien
1018              
1019             John Kingsley
1020              
1021             Jonathan Yu
1022              
1023             Josh Leder
1024              
1025             Kamen Naydenov
1026              
1027             Karen Etheridge
1028              
1029             Kazuhiro Shibuya
1030              
1031             Kevin Old
1032              
1033             Kitamura Akatsuki
1034              
1035             Klaus S. Madsen
1036              
1037             Knut Arne Bjorndal
1038              
1039             Lars Balker Rasmussen
1040              
1041             Lee Johnson
1042              
1043             Leon Brocard
1044              
1045             Lukas Mai
1046              
1047             Magnus Holm
1048              
1049             Maik Fischer
1050              
1051             Mark Fowler
1052              
1053             Mark Grimes
1054              
1055             Mark Stosberg
1056              
1057             Martin McGrath
1058              
1059             Marty Tennison
1060              
1061             Matt S Trout
1062              
1063             Matthew Lineen
1064              
1065             Maksym Komar
1066              
1067             Maxim Vuets
1068              
1069             Michael Gregorowicz
1070              
1071             Michael Harris
1072              
1073             Michael Jemmeson
1074              
1075             Mike Magowan
1076              
1077             Mirko Westermeier
1078              
1079             Mons Anderson
1080              
1081             Moritz Lenz
1082              
1083             Neil Watkiss
1084              
1085             Nic Sandfield
1086              
1087             Nils Diewald
1088              
1089             Oleg Zhelo
1090              
1091             Oliver Kurz
1092              
1093             Olivier Mengue
1094              
1095             Pascal Gaudette
1096              
1097             Paul Evans
1098              
1099             Paul Robins
1100              
1101             Paul Tomlin
1102              
1103             Pavel Shaydo
1104              
1105             Pedro Melo
1106              
1107             Peter Edwards
1108              
1109             Pierre-Yves Ritschard
1110              
1111             Piotr Roszatycki
1112              
1113             Quentin Carbonneaux
1114              
1115             Rafal Pocztarski
1116              
1117             Randal Schwartz
1118              
1119             Rawley Fowler
1120              
1121             Richard Elberger
1122              
1123             Rick Delaney
1124              
1125             Robert Hicks
1126              
1127             Robert Rothenberg
1128              
1129             Robin Lee
1130              
1131             Roland Lammel
1132              
1133             Roy Storey
1134              
1135             Ryan Jendoubi
1136              
1137             Salvador Fandino
1138              
1139             Santiago Zarate
1140              
1141             Sascha Kiefer
1142              
1143             Scott Wiersdorf
1144              
1145             Sebastian Paaske Torholm
1146              
1147             Sergey Zasenko
1148              
1149             Simon Bertrang
1150              
1151             Simone Tampieri
1152              
1153             Shoichi Kaji
1154              
1155             Shu Cho
1156              
1157             Skye Shaw
1158              
1159             Stanis Trendelenburg
1160              
1161             Stefan Adams
1162              
1163             Steffen Ullrich
1164              
1165             Stephan Kulow
1166              
1167             Stephane Este-Gracias
1168              
1169             Stevan Little
1170              
1171             Steve Atkins
1172              
1173             Tatsuhiko Miyagawa
1174              
1175             Terrence Brannon
1176              
1177             Tianon Gravi
1178              
1179             Tomas Znamenacek
1180              
1181             Tudor Constantin
1182              
1183             Ulrich Habel
1184              
1185             Ulrich Kautz
1186              
1187             Uwe Voelker
1188              
1189             Veesh Goldman
1190              
1191             Viacheslav Tykhanovskyi
1192              
1193             Victor Engmark
1194              
1195             Viliam Pucik
1196              
1197             Wes Cravens
1198              
1199             William Lindley
1200              
1201             Yaroslav Korshak
1202              
1203             Yuki Kimoto
1204              
1205             Zak B. Elep
1206              
1207             Zoffix Znet
1208              
1209             =back
1210              
1211             =head1 COPYRIGHT AND LICENSE
1212              
1213             Copyright (C) 2008-2025, Sebastian Riedel and others.
1214              
1215             This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version
1216             2.0.
1217              
1218             =head1 SEE ALSO
1219              
1220             L, L, L.
1221              
1222             =cut