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