Skip to content

Commit

Permalink
renamed HACKS section to APPLICATIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 10, 2014
1 parent 0f6ee26 commit f6b2ed2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
42 changes: 40 additions & 2 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -1094,9 +1094,47 @@ choice.

$ perl -Mojo -E 'say g("mojolicio.us")->dom->html->head->title->text'

=head1 HACKS
=head1 APPLICATIONS

Fun hacks you might not use very often but that might come in handy some day.
Fun L<Mojolicious> application hacks for all occasions.

=head2 Adding a configuration file

Adding a configuration file to your application is as easy as adding a file to
its home directory and loading the plugin L<Mojolicious::Plugin::Config>. The
default name is based on the value of L<Mojolicious/"moniker"> (C<myapp>),
appended with a C<.conf> extension (C<myapp.conf>).

$ mkdir myapp
$ cd myapp
$ touch myapp.pl
$ chmod 744 myapp.pl
$ echo '{name => "my Mojolicious application"};' > myapp.conf

Configuration files themselves are just Perl scripts that return a hash
reference, all settings are available through the method L<Mojo/"config"> and
the helper L<Mojolicious::Plugin::DefaultHelpers/"config">

use Mojolicious::Lite;

plugin 'Config';

my $name = app->config('name');
app->log->debug("Welcome to $name.");

get '/' => 'with_config';

app->start;
__DATA__
@@ with_config.html.ep
<!DOCTYPE html>
<html>
<head><title><%= config 'name' %></title></head>
<body>Welcome to <%= config 'name' %></body>
</html>

Alternatively you can also use configuration files in the JSON format with
L<Mojolicious::Plugin::JSONConfig>.

=head2 Adding commands to Mojolicious

Expand Down
38 changes: 0 additions & 38 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -1006,44 +1006,6 @@ plugin.
@@ alertassets.html.ep
%= javascript "/alertassets.js"

=head2 Adding a configuration file

Adding a configuration file to your application is as easy as adding a file to
its home directory and loading the plugin L<Mojolicious::Plugin::Config>. The
default name is based on the value of L<Mojolicious/"moniker"> (C<myapp>),
appended with a C<.conf> extension (C<myapp.conf>).

$ mkdir myapp
$ cd myapp
$ touch myapp.pl
$ chmod 744 myapp.pl
$ echo '{name => "my Mojolicious application"};' > myapp.conf

Configuration files themselves are just Perl scripts that return a hash
reference, all settings are available through the method L<Mojo/"config"> and
the helper L<Mojolicious::Plugin::DefaultHelpers/"config">

use Mojolicious::Lite;

plugin 'Config';

my $name = app->config('name');
app->log->debug("Welcome to $name.");

get '/' => 'with_config';

app->start;
__DATA__
@@ with_config.html.ep
<!DOCTYPE html>
<html>
<head><title><%= config 'name' %></title></head>
<body>Welcome to <%= config 'name' %></body>
</html>

Alternatively you can also use configuration files in the JSON format with
L<Mojolicious::Plugin::JSONConfig>.

=head1 ADVANCED

Less commonly used and more powerful features.
Expand Down

0 comments on commit f6b2ed2

Please sign in to comment.