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 109 110 99.0
pod 14 15 93.3
total 302 317 95.2


line stmt bran cond sub pod time code
1             package Mojolicious;
2 50     50   67517 use Mojo::Base -base;
  50         134  
  50         479  
3              
4             # "Fry: Shut up and take my money!"
5 50     50   391 use Carp ();
  50         158  
  50         1645  
6 50     50   22345 use Mojo::DynamicMethods -dispatch;
  50         169  
  50         445  
7 50     50   4882 use Mojo::Exception;
  50         166  
  50         2180  
8 50     50   22255 use Mojo::Home;
  50         187  
  50         2572  
9 50     50   4883 use Mojo::Loader;
  50         138  
  50         1956  
10 50     50   23358 use Mojo::Log;
  50         178  
  50         567  
11 50     50   5804 use Mojo::Server;
  50         144  
  50         529  
12 50     50   344 use Mojo::Util;
  50         207  
  50         1929  
13 50     50   9181 use Mojo::UserAgent;
  50         239  
  50         481  
14 50     50   25147 use Mojolicious::Commands;
  50         175  
  50         422  
15 50     50   27557 use Mojolicious::Controller;
  50         211  
  50         432  
16 50     50   22306 use Mojolicious::Plugins;
  50         199  
  50         496  
17 50     50   24499 use Mojolicious::Renderer;
  50         186  
  50         499  
18 50     50   24295 use Mojolicious::Routes;
  50         222  
  50         559  
19 50     50   23886 use Mojolicious::Sessions;
  50         183  
  50         435  
20 50     50   24823 use Mojolicious::Static;
  50         193  
  50         563  
21 50     50   23729 use Mojolicious::Types;
  50         193  
  50         499  
22 50     50   22705 use Mojolicious::Validator;
  50         207  
  50         483  
23 50     50   442 use Scalar::Util ();
  50         165  
  50         131585  
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.33';
61              
62             sub BUILD_DYNAMIC {
63 3237     3237 0 6815 my ($class, $method, $dyn_methods) = @_;
64              
65             return sub {
66 57     57   124 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      
        58      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        68      
        68      
        68      
        68      
        57      
        57      
        57      
        57      
        57      
        57      
        57      
        16      
67 57         190 my $dynamic = $dyn_methods->{$self->renderer}{$method};
68 57 50       243 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 3237         22392 };
72             }
73              
74             sub build_controller {
75 1113     1113 1 2767 my ($self, $tx) = @_;
76              
77             # Embedded application
78 1113         2242 my $stash = {};
79 1113 100 100     7726 if ($tx && (my $sub = $tx->can('stash'))) { ($stash, $tx) = ($tx->$sub, $tx->tx) }
  71         219  
80              
81             # Build default controller
82 1113         3406 my $defaults = $self->defaults;
83 1113         4041 @$stash{keys %$defaults} = values %$defaults;
84 1113         3671 my $c = $self->controller_class->new(app => $self, stash => $stash, tx => $tx);
85 1113   66     3928 $c->{tx} ||= $self->build_tx;
86              
87 1113         2812 return $c;
88             }
89              
90             sub build_tx {
91 1043     1043 1 1963 my $self = shift;
92              
93 1043         4456 my $tx = Mojo::Transaction::HTTP->new;
94 1043         3825 my $max = $self->max_request_size;
95 1043 100       2975 $tx->req->max_message_size($max) if defined $max;
96 1043         3268 $self->plugins->emit_hook(after_build_tx => $tx, $self);
97              
98 1043         2491 return $tx;
99             }
100              
101 233     233 1 799 sub config { Mojo::Util::_stash(config => @_) }
102 1152     1152 1 4114 sub defaults { Mojo::Util::_stash(defaults => @_) }
103              
104             sub dispatch {
105 1022     1022 1 2228 my ($self, $c) = @_;
106              
107 1022         2402 my $plugins = $self->plugins->emit_hook(before_dispatch => $c);
108              
109 1022         3785 my $stash = $c->stash;
110 1022 100       3079 return if $stash->{'mojo.rendered'};
111              
112             # Try to find a static file
113 1015         2856 my $tx = $c->tx;
114 1015 50 66     2984 $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 259     259   779 my $req = $c->req;
119 259         866 my $method = $req->method;
120 259         812 my $path = $req->url->path->to_abs_string;
121 259         1208 $c->helpers->timing->begin('mojo.timer');
122 259         1598 return qq{$method "$path"};
123 1015 100       5744 }) unless $stash->{'mojo.static'};
124              
125             # Routes
126 1015         9032 $plugins->emit_hook(before_routes => $c);
127 1015 100 100     3279 $c->helpers->reply->not_found unless $tx->res->code || $self->routes->dispatch($c) || $tx->res->code;
      100        
128             }
129              
130             sub handler {
131 1023     1023 1 1994 my $self = shift;
132              
133             # Dispatcher has to be last in the chain
134             ++$self->{dispatch}
135             and $self->hook(around_action => \&_action)
136 1022     1022   3433 and $self->hook(around_dispatch => sub { $_[1]->app->dispatch($_[1]) })
137 1023 100 33     3713 unless $self->{dispatch};
      33        
138              
139             # Process with chain
140 1023         3654 my $c = $self->build_controller(@_);
141 1023         3099 $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 1023 100       3693 unless $c->stash->{'mojo.rendered'};
146             }
147              
148 8787     8787 1 27309 sub helper { shift->renderer->add_helper(@_) }
149              
150 270     270 1 1019 sub hook { shift->plugins->on(@_) }
151              
152             sub new {
153 104 50   104 1 12733 my $self = shift->SUPER::new((ref $_[0] ? %{shift()} : @_), @Mojo::Server::ARGS_OVERRIDE);
  0         0  
154              
155 104         610 my $home = $self->home;
156 104         238 push @{$self->renderer->paths}, $home->child('templates')->to_string;
  104         513  
157 104         510 push @{$self->static->paths}, $home->child('public')->to_string;
  104         530  
158              
159             # Default to controller and application namespace
160 104         347 my $controller = "@{[ref $self]}::Controller";
  104         543  
161 104         644 my $r = $self->preload_namespaces([$controller])->routes->namespaces([$controller, ref $self]);
162              
163 104         645 $self->plugin($_) for qw(HeaderCondition DefaultHelpers TagHelpers EPLRenderer EPRenderer);
164              
165             # Exception handling should be first in chain
166 104         767 $self->hook(around_dispatch => \&_exception);
167              
168 104         617 $self->startup;
169 104         541 $self->warmup;
170              
171 104         465 return $self;
172             }
173              
174             sub plugin {
175 604     604 1 1285 my $self = shift;
176 604         2080 $self->plugins->register_plugin(shift, $self, @_);
177             }
178              
179 157     157 1 764 sub server { $_[0]->plugins->emit_hook(before_server_start => @_[1, 0]) }
180              
181             sub start {
182 28     28 1 4470 my $self = shift;
183 28         122 $_->warmup for $self->static, $self->renderer;
184 28 100       143 return $self->commands->run(@_ ? @_ : @ARGV);
185             }
186              
187       68 1   sub startup { }
188              
189 104     104 1 215 sub warmup { Mojo::Loader::load_classes $_ for @{shift->preload_namespaces} }
  104         764  
190              
191             sub _action {
192 603     603   1999 my ($next, $c, $action, $last) = @_;
193 603         2584 my $val = $action->($c);
194 573 100 100 0   5587 $val->catch(sub { $c->helpers->reply->exception(shift) }) if Scalar::Util::blessed $val && $val->isa('Mojo::Promise');
  0         0  
195 573         3983 return $val;
196             }
197              
198 130 100   130   2740 sub _die { CORE::die ref $_[0] ? $_[0] : Mojo::Exception->new(shift)->trace }
199              
200             sub _exception {
201 1023     1023   2277 my ($next, $c) = @_;
202 1023         5698 local $SIG{__DIE__} = \&_die;
203 1023 100       2122 $c->helpers->reply->exception($@) unless eval { $next->(); 1 };
  1023         2736  
  963         8286  
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             # Change name of cookie used for all sessions
517             $app->sessions->cookie_name('mysession');
518              
519             # Disable SameSite feature
520             $app->sessions->samesite(undef);
521              
522             =head2 static
523              
524             my $static = $app->static;
525             $app = $app->static(Mojolicious::Static->new);
526              
527             For serving static files from your C directories, defaults to a L object.
528              
529             # Add another "public" directory
530             push @{$app->static->paths}, '/home/sri/public';
531              
532             # Add another "public" directory with higher precedence
533             unshift @{$app->static->paths}, '/home/sri/themes/blue/public';
534              
535             # Add another class with static files in DATA section
536             push @{$app->static->classes}, 'Mojolicious::Plugin::Fun';
537              
538             # Remove built-in favicon
539             delete $app->static->extra->{'favicon.ico'};
540              
541             =head2 types
542              
543             my $types = $app->types;
544             $app = $app->types(Mojolicious::Types->new);
545              
546             Responsible for connecting file extensions with MIME types, defaults to a L object.
547              
548             # Add custom MIME type
549             $app->types->type(twt => 'text/tweet');
550              
551             =head2 ua
552              
553             my $ua = $app->ua;
554             $app = $app->ua(Mojo::UserAgent->new);
555              
556             A full featured HTTP user agent for use in your applications, defaults to a L object.
557              
558             # Perform blocking request
559             say $app->ua->get('example.com')->result->body;
560              
561             =head2 validator
562              
563             my $validator = $app->validator;
564             $app = $app->validator(Mojolicious::Validator->new);
565              
566             Validate values, defaults to a L object.
567              
568             # Add validation check
569             $app->validator->add_check(foo => sub ($v, $name, $value) {
570             return $value ne 'foo';
571             });
572              
573             # Add validation filter
574             $app->validator->add_filter(quotemeta => sub ($v, $name, $value) {
575             return quotemeta $value;
576             });
577              
578             =head1 METHODS
579              
580             L inherits all methods from L and implements the following new ones.
581              
582             =head2 build_controller
583              
584             my $c = $app->build_controller;
585             my $c = $app->build_controller(Mojo::Transaction::HTTP->new);
586             my $c = $app->build_controller(Mojolicious::Controller->new);
587              
588             Build default controller object with L.
589              
590             # Render template from application
591             my $foo = $app->build_controller->render_to_string(template => 'foo');
592              
593             =head2 build_tx
594              
595             my $tx = $app->build_tx;
596              
597             Build L object and emit L hook.
598              
599             =head2 config
600              
601             my $hash = $app->config;
602             my $foo = $app->config('foo');
603             $app = $app->config({foo => 'bar', baz => 23});
604             $app = $app->config(foo => 'bar', baz => 23);
605              
606             Application configuration.
607              
608             # Remove value
609             my $foo = delete $app->config->{foo};
610              
611             # Assign multiple values at once
612             $app->config(foo => 'test', bar => 23);
613              
614             =head2 defaults
615              
616             my $hash = $app->defaults;
617             my $foo = $app->defaults('foo');
618             $app = $app->defaults({foo => 'bar', baz => 23});
619             $app = $app->defaults(foo => 'bar', baz => 23);
620              
621             Default values for L, assigned for every new request.
622              
623             # Remove value
624             my $foo = delete $app->defaults->{foo};
625              
626             # Assign multiple values at once
627             $app->defaults(foo => 'test', bar => 23);
628              
629             =head2 dispatch
630              
631             $app->dispatch(Mojolicious::Controller->new);
632              
633             The heart of every L application, calls the L and L dispatchers for every request
634             and passes them a L object.
635              
636             =head2 handler
637              
638             $app->handler(Mojo::Transaction::HTTP->new);
639             $app->handler(Mojolicious::Controller->new);
640              
641             Sets up the default controller and emits the L hook for every request.
642              
643             =head2 helper
644              
645             $app->helper(foo => sub {...});
646              
647             Add or replace a helper that will be available as a method of the controller object and the application object, as well
648             as a function in C templates. For a full list of helpers that are available by default see
649             L and L.
650              
651             # Helper
652             $app->helper(cache => sub { state $cache = {} });
653              
654             # Application
655             $app->cache->{foo} = 'bar';
656             my $result = $app->cache->{foo};
657              
658             # Controller
659             $c->cache->{foo} = 'bar';
660             my $result = $c->cache->{foo};
661              
662             # Template
663             % cache->{foo} = 'bar';
664             %= cache->{foo}
665              
666             =head2 hook
667              
668             $app->hook(after_dispatch => sub {...});
669              
670             Extend L with hooks, which allow code to be shared with all requests indiscriminately, for a full list of
671             available hooks see L.
672              
673             # Dispatchers will not run if there's already a response code defined
674             $app->hook(before_dispatch => sub ($c) {
675             $c->render(text => 'Skipped static file server and router!')
676             if $c->req->url->path->to_route =~ /do_not_dispatch/;
677             });
678              
679             =head2 new
680              
681             my $app = Mojolicious->new;
682             my $app = Mojolicious->new(moniker => 'foo_bar');
683             my $app = Mojolicious->new({moniker => 'foo_bar'});
684              
685             Construct a new L application and call L. Will automatically detect your home directory. Also
686             sets up the renderer, static file server, a default set of plugins and an L hook with the default
687             exception handling.
688              
689             =head2 plugin
690              
691             $app->plugin('some_thing');
692             $app->plugin('some_thing', foo => 23);
693             $app->plugin('some_thing', {foo => 23});
694             $app->plugin('SomeThing');
695             $app->plugin('SomeThing', foo => 23);
696             $app->plugin('SomeThing', {foo => 23});
697             $app->plugin('MyApp::Plugin::SomeThing');
698             $app->plugin('MyApp::Plugin::SomeThing', foo => 23);
699             $app->plugin('MyApp::Plugin::SomeThing', {foo => 23});
700              
701             Load a plugin, for a full list of example plugins included in the L distribution see
702             L.
703              
704             =head2 server
705              
706             $app->server(Mojo::Server->new);
707              
708             Emits the L hook.
709              
710             =head2 start
711              
712             $app->start;
713             $app->start(@ARGV);
714              
715             Start the command line interface for your application. For a full list of commands that are available by default see
716             L. Note that the options C<-h>/C<--help>, C<--home> and C<-m>/C<--mode>, which are
717             shared by all commands, will be parsed from C<@ARGV> during compile time.
718              
719             # Always start daemon
720             $app->start('daemon', '-l', 'http://*:8080');
721              
722             =head2 startup
723              
724             $app->startup;
725              
726             This is your main hook into the application, it will be called at application startup. Meant to be overloaded in a
727             subclass.
728              
729             sub startup ($self) {...}
730              
731             =head2 warmup
732              
733             $app->warmup;
734              
735             Preload classes from L for future use.
736              
737             =head1 HELPERS
738              
739             In addition to the L and L above you can also call helpers on L objects. This
740             includes all helpers from L and L. Note that
741             application helpers are always called with a new default controller object, so they can't depend on or change
742             controller state, which includes request, response and stash.
743              
744             # Call helper
745             say $app->dumper({foo => 'bar'});
746              
747             # Longer version
748             say $app->build_controller->helpers->dumper({foo => 'bar'});
749              
750             =head1 BUNDLED FILES
751              
752             The L distribution includes a few files with different licenses that have been bundled for internal use.
753              
754             =head2 Mojolicious Artwork
755              
756             Copyright (C) 2010-2023, Sebastian Riedel.
757              
758             Licensed under the CC-SA License, Version 4.0 L.
759              
760             =head2 jQuery
761              
762             Copyright (C) jQuery Foundation.
763              
764             Licensed under the MIT License, 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             =head1 CODE NAMES
780              
781             Every major release of L has a code name, these are the ones that have been used in the past.
782              
783             9.0, C (U+1F9C7)
784              
785             8.0, C (U+1F9B9)
786              
787             7.0, C (U+1F369)
788              
789             6.0, C (U+1F37B)
790              
791             5.0, C (U+1F42F)
792              
793             4.0, C (U+1F3A9)
794              
795             3.0, C (U+1F308)
796              
797             2.0, C (U+1F343)
798              
799             1.0, C (U+2744)
800              
801             =head1 SPONSORS
802              
803             =over 2
804              
805             =item
806              
807             L sponsored the creation of the Mojolicious logo (designed by Nicolai Graesdal) and transferred
808             its copyright to Sebastian Riedel.
809              
810             =item
811              
812             Some of the work on this distribution has been sponsored by L.
813              
814             =back
815              
816             =head1 AUTHORS
817              
818             L is an open source project that relies on the tireless support of its contributors.
819              
820             =head2 Project Founder
821              
822             Sebastian Riedel, C
823              
824             =head2 Core Developers
825              
826             Current voting members of the core team in alphabetical order:
827              
828             =over 2
829              
830             CandyAngel, C
831              
832             Christopher Rasch-Olsen Raa, C
833              
834             Dan Book, C
835              
836             Jan Henning Thorsen, C
837              
838             Joel Berger, C
839              
840             Marcus Ramberg, C
841              
842             =back
843              
844             The following members of the core team are currently on hiatus:
845              
846             =over 2
847              
848             Abhijit Menon-Sen, C
849              
850             Glen Hinkle, C
851              
852             =back
853              
854             =head2 Contributors
855              
856             In alphabetical order:
857              
858             =over 2
859              
860             Adam Kennedy
861              
862             Adriano Ferreira
863              
864             Al Newkirk
865              
866             Alex Efros
867              
868             Alex Salimon
869              
870             Alexander Karelas
871              
872             Alexey Likhatskiy
873              
874             Anatoly Sharifulin
875              
876             Andre Parker
877              
878             Andre Vieth
879              
880             Andreas Guldstrand
881              
882             Andreas Jaekel
883              
884             Andreas Koenig
885              
886             Andrew Fresh
887              
888             Andrew Nugged
889              
890             Andrey Khozov
891              
892             Andrey Kuzmin
893              
894             Andy Grundman
895              
896             Andy Lester
897              
898             Aristotle Pagaltzis
899              
900             Ashley Dev
901              
902             Ask Bjoern Hansen
903              
904             Audrey Tang
905              
906             Ben Tyler
907              
908             Ben van Staveren
909              
910             Benjamin Erhart
911              
912             Bernhard Graf
913              
914             Breno G. de Oliveira
915              
916             Brian Duggan
917              
918             Brian Medley
919              
920             Burak Gursoy
921              
922             Ch Lamprecht
923              
924             Charlie Brady
925              
926             Chas. J. Owens IV
927              
928             Chase Whitener
929              
930             Chris Scheller
931              
932             Christian Hansen
933              
934             chromatic
935              
936             Curt Tilmes
937              
938             Daniel Kimsey
939              
940             Daniel Mantovani
941              
942             Danijel Tasov
943              
944             Dagfinn Ilmari Manns�ker
945              
946             Danny Thomas
947              
948             David Davis
949              
950             David Webb
951              
952             Diego Kuperman
953              
954             Dmitriy Shalashov
955              
956             Dmitry Konstantinov
957              
958             Dominik Jarmulowicz
959              
960             Dominique Dumont
961              
962             Dotan Dimet
963              
964             Douglas Christopher Wilson
965              
966             Elmar S. Heeb
967              
968             Ettore Di Giacinto
969              
970             Eugen Konkov
971              
972             Eugene Toropov
973              
974             Flavio Poletti
975              
976             Gisle Aas
977              
978             Graham Barr
979              
980             Graham Knop
981              
982             Heiko Jansen
983              
984             Henry Tang
985              
986             Hideki Yamamura
987              
988             Hiroki Toyokawa
989              
990             Ian Goodacre
991              
992             Ilya Chesnokov
993              
994             Ilya Rassadin
995              
996             James Duncan
997              
998             Jan Jona Javorsek
999              
1000             Jan Schmidt
1001              
1002             Jaroslav Muhin
1003              
1004             Jesse Vincent
1005              
1006             Johannes Plunien
1007              
1008             John Kingsley
1009              
1010             Jonathan Yu
1011              
1012             Josh Leder
1013              
1014             Kamen Naydenov
1015              
1016             Karen Etheridge
1017              
1018             Kazuhiro Shibuya
1019              
1020             Kevin Old
1021              
1022             Kitamura Akatsuki
1023              
1024             Klaus S. Madsen
1025              
1026             Knut Arne Bjorndal
1027              
1028             Lars Balker Rasmussen
1029              
1030             Lee Johnson
1031              
1032             Leon Brocard
1033              
1034             Lukas Mai
1035              
1036             Magnus Holm
1037              
1038             Maik Fischer
1039              
1040             Mark Fowler
1041              
1042             Mark Grimes
1043              
1044             Mark Stosberg
1045              
1046             Martin McGrath
1047              
1048             Marty Tennison
1049              
1050             Matt S Trout
1051              
1052             Matthew Lineen
1053              
1054             Maksym Komar
1055              
1056             Maxim Vuets
1057              
1058             Michael Gregorowicz
1059              
1060             Michael Harris
1061              
1062             Michael Jemmeson
1063              
1064             Mike Magowan
1065              
1066             Mirko Westermeier
1067              
1068             Mons Anderson
1069              
1070             Moritz Lenz
1071              
1072             Neil Watkiss
1073              
1074             Nic Sandfield
1075              
1076             Nils Diewald
1077              
1078             Oleg Zhelo
1079              
1080             Olivier Mengue
1081              
1082             Pascal Gaudette
1083              
1084             Paul Evans
1085              
1086             Paul Robins
1087              
1088             Paul Tomlin
1089              
1090             Pavel Shaydo
1091              
1092             Pedro Melo
1093              
1094             Peter Edwards
1095              
1096             Pierre-Yves Ritschard
1097              
1098             Piotr Roszatycki
1099              
1100             Quentin Carbonneaux
1101              
1102             Rafal Pocztarski
1103              
1104             Randal Schwartz
1105              
1106             Rawley Fowler
1107              
1108             Richard Elberger
1109              
1110             Rick Delaney
1111              
1112             Robert Hicks
1113              
1114             Robert Rothenberg
1115              
1116             Robin Lee
1117              
1118             Roland Lammel
1119              
1120             Roy Storey
1121              
1122             Ryan Jendoubi
1123              
1124             Salvador Fandino
1125              
1126             Santiago Zarate
1127              
1128             Sascha Kiefer
1129              
1130             Scott Wiersdorf
1131              
1132             Sebastian Paaske Torholm
1133              
1134             Sergey Zasenko
1135              
1136             Simon Bertrang
1137              
1138             Simone Tampieri
1139              
1140             Shoichi Kaji
1141              
1142             Shu Cho
1143              
1144             Skye Shaw
1145              
1146             Stanis Trendelenburg
1147              
1148             Stefan Adams
1149              
1150             Steffen Ullrich
1151              
1152             Stephan Kulow
1153              
1154             Stephane Este-Gracias
1155              
1156             Stevan Little
1157              
1158             Steve Atkins
1159              
1160             Tatsuhiko Miyagawa
1161              
1162             Terrence Brannon
1163              
1164             Tianon Gravi
1165              
1166             Tomas Znamenacek
1167              
1168             Tudor Constantin
1169              
1170             Ulrich Habel
1171              
1172             Ulrich Kautz
1173              
1174             Uwe Voelker
1175              
1176             Veesh Goldman
1177              
1178             Viacheslav Tykhanovskyi
1179              
1180             Victor Engmark
1181              
1182             Viliam Pucik
1183              
1184             Wes Cravens
1185              
1186             William Lindley
1187              
1188             Yaroslav Korshak
1189              
1190             Yuki Kimoto
1191              
1192             Zak B. Elep
1193              
1194             Zoffix Znet
1195              
1196             =back
1197              
1198             =head1 COPYRIGHT AND LICENSE
1199              
1200             Copyright (C) 2008-2023, Sebastian Riedel and others.
1201              
1202             This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version
1203             2.0.
1204              
1205             =head1 SEE ALSO
1206              
1207             L, L, L.
1208              
1209             =cut