Acme-CPANModulesBundle-Import-MojoliciousAdvent-2017

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "Mojo::UserAgent::Transactor" : "0",
            "Mojo::Util" : "0",
            "Mojo::XMLRPC" : "0",
            "Mojo::mysql" : "0",
            "Mojolicious" : "0",
            "Mojolicious::Command" : "0",
            "Mojolicious::Command::bulkget" : "0",
            "Mojolicious::Command::cgi" : "0",
            "Mojolicious::Command::cpanify" : "0",
            "Mojolicious::Command::daemon" : "0",
            "Mojolicious::Command::eval" : "0",
            "Mojolicious::Command::generate" : "0",
            "Mojolicious::Command::generate::app" : "0",
            "Mojolicious::Command::generate::lite_app" : "0",
            "Mojolicious::Command::generate::makefile" : "0",
            "Mojolicious::Command::generate::plugin" : "0",
            "Mojolicious::Command::get" : "0",
            "Mojolicious::Command::inflate" : "0",
            "Mojolicious::Command::nopaste" : "0",
            "Mojolicious::Command::prefork" : "0",
            "Mojolicious::Command::psgi" : "0",

Makefile.PL  view on Meta::CPAN



my %FallbackPrereqs = (
  "File::Spec" => 0,
  "IO::Handle" => 0,
  "IPC::Open3" => 0,
  "Test::More" => 0
);


unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
  delete $WriteMakefileArgs{TEST_REQUIRES};
  delete $WriteMakefileArgs{BUILD_REQUIRES};
  $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
}

delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
  unless eval { ExtUtils::MakeMaker->VERSION(6.52) };

WriteMakefile(%WriteMakefileArgs);

devdata/https_mojolicious.io_blog_2017_12_05_day-5-your-apps-built-in-commands  view on Meta::CPAN

  -h, --help          Get more information on a specific command
      --home <path>   Path to home directory of your application, defaults to
                      the value of MOJO_HOME or auto-detection
  -m, --mode <name>   Operating mode for your application, defaults to the
                      value of MOJO_MODE/PLACK_ENV or "development"

Commands:
cgi       Start application with CGI
cpanify   Upload distribution to CPAN
daemon    Start application with HTTP and WebSocket server
eval      Run code against application
generate  Generate files and directories from templates
get       Perform HTTP request
inflate   Inflate embedded files to real files
prefork   Start application with pre-forking HTTP and WebSocket server
psgi      Start application with PSGI
routes    Show available routes
test      Run tests
version   Show versions of available modules

See 'APPLICATION help COMMAND' for more information on a specific command.

devdata/https_mojolicious.io_blog_2017_12_05_day-5-your-apps-built-in-commands  view on Meta::CPAN

<li>See lots more examples in the <a href="http://mojolicious.org/perldoc/Mojolicious/Command/get#SYNOPSIS">documentation</a>.</li>
</ul>

<p>But I haven&#39;t even touched on its coolest feature yet.
This command also works on your application when you request a relative url.
This is so handy for debugging requests during rapid development; you don&#39;t even need a browser!</p>

<pre><code>perl santa.pl get /meet/rudolph &#39;p&#39; text
</code></pre>

<h3>The eval Command</h3>

<p>Finally in this whirlwind tour, I&#39;ll show you my favorite command.
The <a href="http://mojolicious.org/perldoc/Mojolicious/Command/eval"><code>eval</code></a> command.
This command has the magic power to run one-off commands using your application!
The application is available as <code>app</code> in your one-liner.</p>

<p>So say you can&#39;t figure out what is wrong with your configuration, just ask it to dump what it thinks its configuration is</p>

<pre><code>perl myapp.pl eval -v &#39;app-&gt;home&#39;
perl myapp.pl eval -V &#39;app-&gt;config&#39;
</code></pre>

<p>The <code>-v</code> flag prints the string result of the last statement to STDOUT, the <code>-V</code> flag does the same but for data structures.
Maybe you want to see why it can&#39;t find your templates.</p>

<pre><code>perl myapp.pl eval -V &#39;app-&gt;renderer-&gt;paths&#39;
</code></pre>

<p>This is especially helpful once you have database interactions setup via some model layer.
If you want to see the result for some query, just check.</p>

<pre><code>perl myapp.pl eval -V &#39;app-&gt;model-&gt;users-&gt;find({name =&gt; &quot;Joel&quot;})&#39;
</code></pre>

<p>Though of course that will depend on how your model layer works.
Or maybe you want to deploy your schema, or roll it back.</p>

<pre><code>perl myapp.pl eval &#39;app-&gt;pg-&gt;migrations-&gt;migrate&#39;
</code></pre>

<p>Or just check that the database is reachable.</p>

<pre><code>perl myapp.pl eval -V &#39;app-&gt;pg-&gt;db-&gt;query(&quot;SELECT NOW()&quot;)-&gt;hash&#39;
</code></pre>

<p>These last two database examples assumed that your app was using <a href="http://mojolicious.org/perldoc/Mojo/Pg">Mojo::Pg</a> but similar one-liners could work for any database that your app knows about.</p>

<p>There really is nothing like debugging or administering your application without having to copy and paste a bunch of your logic from your app to some script.
Although if you really find yourself using the <code>eval</code> command for the same tasks often ... well that should wait until tomorrow.</p>

              </section>
              <small><p><a href="https://commons.wikimedia.org/w/index.php?curid=44576486">Image</a> by <a href="//commons.wikimedia.org/w/index.php?title=User:Gsaisudha75&amp;action=edit&amp;redlink=1" title="User:Gsaisudha75 (page does not exist)">...
</small>

              <p class="tags">
                <span>Tagged in </span>:
                  <a href="/blog/tag/advent/">advent</a>,
                  <a href="/blog/tag/command/">command</a>,
                  <a href="/blog/tag/debugging/">debugging</a>,

devdata/https_mojolicious.io_blog_2017_12_06_day-6-adding-your-own-commands  view on Meta::CPAN

              <section id="section-1">
                  <p>Everyone has written those one-off administration or check scripts.
There are probably a few cluttering your project root or bin directory right now.
Those have a problem beyond just the clutter: duplication.</p>

<p>Programmers hate duplication because of skew.
If code gets improved in one place, it is unlikely to be improved in all places, unless there is only the one.
So that script you wrote a while back, the one with the database connection you hand-rolled, is that still correct?</p>

<p>In the <a href="/blog/2017/12/05/day-5-your-apps-built-in-commands">previous article in this series</a> I talked about the built-in commands available to your application.
The final command was <a href="http://mojolicious.org/perldoc/Mojolicious/Command/eval"><code>eval</code></a>.
I mentioned that when combined with predefined behaviors, the command could be great for administrative tasks.
That&#39;s true, but you need to know what to eval in order to do so.</p>

<p>To formalize that process, we can go one step further: defining our own commands.
By doing this your application&#39;s administative behaviors can take arguemnts and provide optional switches as well as give usage messages.
In this way these administative commands decouple themselves from knowledge of the application&#39;s internals and become useful to a broader set of users.</p>

              </section>
              <section id="section-2">
                  <h2>What is a Command?</h2>

<p>Structurally, a command is just a class that inherits from <a href="http://mojolicious.org/perldoc/Mojolicious/Command">Mojolicious::Command</a> and implements a <code>run</code> method.
The method is passed an instance of the command class and the arguments given on the command line.
The command has the application as an attribute.
Just as the <code>eval</code> command demonstrated, the real power of the command comes from having access to an instance of the application, including its relevant configuration and methods.</p>

<p>By default your application looks for available commands in the namespace <code>Mojolicious::Command</code>.
As we saw before, several are available built-in to the system.
However others are available from CPAN, for example, I have a <a href="https://metacpan.org/pod/Mojolicious::Command::nopaste">nopaste clone</a> that when installed is available via your application or the <code>mojo</code> executable.</p>

<p>Your application can add to or even replace the default namespace search path by setting <a href="http://mojolicious.org/perldoc/Mojolicious#commands"><code>app-&gt;commands-&gt;namespaces</code></a>.
My <a href="https://metacpan.org/pod/Galileo">Galileo</a> CMS adds a command namespace so that its deploy command is available as <code>galileo deploy</code> but not as <code>mojo deploy</code>.
Meanwhile plugins that your app loads can add to the namespaces.
The <a href="http://mojolicious.org/perldoc/Minion">Minion</a> job queue is added to your application as a plugin, it appends <code>Minion::command</code> to your command namespaces so that your application has access to the minion commands like star...

devdata/https_mojolicious.io_blog_2017_12_06_day-6-adding-your-own-commands  view on Meta::CPAN

This is much like the action callbacks we saw before, but by keeping it in a separate class the application class is easier to read.</p>

<p>Finally we define the database schema.
This is a format common to the Mojo-flavored database modules, like <a href="http://mojolicious.org/perldoc/Mojo/Pg">Mojo::Pg</a>, <a href="https://metacpan.org/pod/Mojo::mysql">Mojo::mysql</a>, and <a href="https://metacpan.org/pod/Mojo::SQLite">Moj...
Each section is defined with a version number and the word <code>up</code> or <code>down</code>.
When migrating versions, it will apply each change set from the current version (beginning at 0) until the version you request.
If you don&#39;t request a version it gets the highest version.</p>

<p>Now that all that is done, we can try it out!</p>

<pre><code>$ perl bin/myweatherapp eval -V &#39;app-&gt;weather-&gt;fetch(&quot;Chicago&quot;)&#39;
</code></pre>

<p>If you&#39;ve configured your appid correctly you should get a dump of weather data about my home city.</p>

<h3>The Commands</h3>

<p>Well finally we have arrived at the whole reason we started this endeavour: the commands!</p>

<p>This example has two different uses for commands.
The first use is to deploy our database schema or to upgrade it should it change.

devdata/https_mojolicious.io_blog_2017_12_06_day-6-adding-your-own-commands  view on Meta::CPAN

  for my $search (@args) {
    my $result = $app-&gt;weather-&gt;fetch($search);
    $app-&gt;weather-&gt;insert($search, $result);
  }
}

1;
</code></pre>

<p>Now you can see that both of these commands are fairly simple.
Indeed they <strong>could</strong> be done by smart use of the <code>eval</code> command.
But see how the <code>deploy</code> command can take an optional version parameter.
Similarly the <code>fetch_weather</code> command can either take search terms on the command line or get them from the configuration file.
And both have a description and usage information to help a new user understand how they work.
Try running</p>

<pre><code>$ perl bin/myweatherapp help
</code></pre>

<p>You should see those commands listed (you shouldn&#39;t see them via <code>mojo help</code>).
To load some data try running</p>

devdata/https_mojolicious.io_blog_2017_12_16_day-16-the-secret-life-of-sessions  view on Meta::CPAN

This also therefore implies that as long as you visit often enough (before any one cookie expires) and your data continues to validate against the secret, your session can last forever.</p>

<h2>Secret Security</h2>

<p>Now, one other thing you should see is that in your application&#39;s log output, you should have a message like</p>

<pre><code>Your secret passphrase needs to be changed
</code></pre>

<p>This happens because you are using the default secret for the application.
This default is just the name of the script, as you can see via the <a href="/blog/2017/12/05/day-5-your-apps-built-in-commands">eval command</a></p>

<pre><code>$ perl myapp.pl eval -V &#39;app-&gt;secrets&#39;
[
  &quot;myapp&quot;
]
</code></pre>

<p>This secret is not secure both because it is short and because it is easy to guess.
With a trivial application like this you might not need to worry about forgery, as you would with say a session that tracks user logins.
But who knows, perhaps you are going to award a prize to the user for the most requests made!
Let&#39;s play it safe.</p>

devdata/https_mojolicious.io_blog_2017_12_23_day-23-one-liners-for-fun-and-profit  view on Meta::CPAN

              <section id="section-1">
                  <p>Perl is well-known for its <a href="http://www.catonmat.net/download/perl1line.txt">one-liners</a>: short programs written as part of the <a href="http://perldoc.perl.org/perlrun.html">command line invocation of the interpreter</...
Certainly every programmer or sysadmin has the need, from time to time, to do a quick one-off task programmatically.
Such tasks can be done with a full script, to be sure, but once you get the hang of writing them, one-liners can save the time and hassle of actually doing so.</p>

<p>These tasks may include removing unwanted lines from files, collecting data from logs, or even a quick proof-of-concept of something that would become a script later.
They can read lines in files, even multiple files, can operate on files in-place, can read from STDIN as a pipe.
But while one-liners have been tools of the trade for these activities, certainly no such thing would be practical for web tasks, right?</p>

<p>But of course, on <a href="https://mojolicious.io/blog/2017/12/05/day-5-your-apps-built-in-commands/">day 5</a> and <a href="https://mojolicious.io/blog/2017/12/06/day-6-adding-your-own-commands/">day 6</a> of this series that we saw that we can b...
We have even seen how to use the <a href="http://mojolicious.org/perldoc/Mojolicious/Command/eval">eval</a> command to run a one-liner against your app.
So could we take this further?</p>

<p>Could we do remote data fetching and manipulation as a one-liner?
Could we build an entire web application as a one-liner?
Would I be asking if the answer was no?</p>

              </section>
              <section id="section-2">
                  <h2>A Note on Readability</h2>

lib/Acme/CPANModules/Import/MojoliciousAdvent/2017.pm  view on Meta::CPAN

package Acme::CPANModules::Import::MojoliciousAdvent::2017;

our $DATE = '2018-12-30'; # DATE
our $VERSION = '0.001'; # VERSION

our $LIST = {description=>"This list is generated by extracting module names mentioned in [https://mojolicious.io/page/advent/2017/] (retrieved on 2018-12-30). Visit the URL for the full contents.",entries=>[{module=>"App::cpanminus"},{module=>"Mojo:...

1;
# ABSTRACT: Modules mentioned in Mojolicious Advent Calendar 2017

__END__

=pod

=encoding UTF-8

lib/Acme/CPANModules/Import/MojoliciousAdvent/2017.pm  view on Meta::CPAN

=item * L<Mojo::Pg>

=item * L<Mojo::UserAgent>

=item * L<Mojolicious::Command::cgi>

=item * L<Mojolicious::Command::cpanify>

=item * L<Mojolicious::Command::daemon>

=item * L<Mojolicious::Command::eval>

=item * L<Mojolicious::Command::generate>

=item * L<Mojolicious::Command::generate::app>

=item * L<Mojolicious::Command::generate::lite_app>

=item * L<Mojolicious::Command::generate::makefile>

=item * L<Mojolicious::Command::generate::plugin>

lib/Acme/CPANModules/Import/MojoliciousAdvent/2017_12_05.pm  view on Meta::CPAN

package Acme::CPANModules::Import::MojoliciousAdvent::2017_12_05;

our $DATE = '2018-12-30'; # DATE
our $VERSION = '0.001'; # VERSION

our $LIST = {description=>"This list is generated by extracting module names mentioned in [https://mojolicious.io/blog/2017/12/05/day-5-your-apps-built-in-commands] (retrieved on 2018-12-30). Visit the URL for the full contents.",entries=>[{module=>"...

1;
# ABSTRACT: Modules mentioned in Mojolicious Advent Calendar 2017 (day 05)

__END__

=pod

=encoding UTF-8

lib/Acme/CPANModules/Import/MojoliciousAdvent/2017_12_05.pm  view on Meta::CPAN

=item * L<Mojo::Pg>

=item * L<Mojo::UserAgent>

=item * L<Mojolicious::Command::cgi>

=item * L<Mojolicious::Command::cpanify>

=item * L<Mojolicious::Command::daemon>

=item * L<Mojolicious::Command::eval>

=item * L<Mojolicious::Command::generate>

=item * L<Mojolicious::Command::generate::app>

=item * L<Mojolicious::Command::generate::lite_app>

=item * L<Mojolicious::Command::generate::makefile>

=item * L<Mojolicious::Command::generate::plugin>

lib/Acme/CPANModules/Import/MojoliciousAdvent/2017_12_06.pm  view on Meta::CPAN

package Acme::CPANModules::Import::MojoliciousAdvent::2017_12_06;

our $DATE = '2018-12-30'; # DATE
our $VERSION = '0.001'; # VERSION

our $LIST = {description=>"This list is generated by extracting module names mentioned in [https://mojolicious.io/blog/2017/12/06/day-6-adding-your-own-commands] (retrieved on 2018-12-30). Visit the URL for the full contents.",entries=>[{module=>"Gal...

1;
# ABSTRACT: Modules mentioned in Mojolicious Advent Calendar 2017 (day 06)

__END__

=pod

=encoding UTF-8

lib/Acme/CPANModules/Import/MojoliciousAdvent/2017_12_06.pm  view on Meta::CPAN

=item * L<Mojo::Pg>

=item * L<Mojo::SQLite>

=item * L<Mojo::mysql>

=item * L<Mojolicious>

=item * L<Mojolicious::Command>

=item * L<Mojolicious::Command::eval>

=item * L<Mojolicious::Command::generate>

=item * L<Mojolicious::Command::nopaste>

=item * L<Mojolicious::Commands>

=back

=head1 HOMEPAGE

lib/Acme/CPANModules/Import/MojoliciousAdvent/2017_12_23.pm  view on Meta::CPAN

package Acme::CPANModules::Import::MojoliciousAdvent::2017_12_23;

our $DATE = '2018-12-30'; # DATE
our $VERSION = '0.001'; # VERSION

our $LIST = {description=>"This list is generated by extracting module names mentioned in [https://mojolicious.io/blog/2017/12/23/day-23-one-liners-for-fun-and-profit] (retrieved on 2018-12-30). Visit the URL for the full contents.",entries=>[{module...

1;
# ABSTRACT: Modules mentioned in Mojolicious Advent Calendar 2017 (day 23)

__END__

=pod

=encoding UTF-8

lib/Acme/CPANModules/Import/MojoliciousAdvent/2017_12_23.pm  view on Meta::CPAN

=item * L<Mojo::File>

=item * L<Mojo::JSON>

=item * L<Mojo::Message::Response>

=item * L<Mojo::UserAgent>

=item * L<Mojo::Util>

=item * L<Mojolicious::Command::eval>

=item * L<Mojolicious::Command::get>

=item * L<Mojolicious::Lite>

=item * L<ojo>

=item * L<ojoBox>

=back

t/00-compile.t  view on Meta::CPAN

            $^X, @switches, '-e', "require q[$lib]"))
        if $ENV{PERL_COMPILE_TEST_DEBUG};

    my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
    binmode $stderr, ':crlf' if $^O eq 'MSWin32';
    my @_warnings = <$stderr>;
    waitpid($pid, 0);
    is($?, 0, "$lib loaded ok");

    shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
        and not eval { +require blib; blib->VERSION('1.01') };

    if (@_warnings)
    {
        warn @_warnings;
        push @warnings, @_warnings;
    }
}





( run in 1.246 second using v1.01-cache-2.11-cpan-ceb78f64989 )