File Coverage

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


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