Browse Source

Merge pull request #1053 from jberger/perl

Perl: General Readme + Mojolicious Updates
Hamilton Turner 11 years ago
parent
commit
d73528094e

+ 37 - 0
frameworks/Perl/README.md

@@ -0,0 +1,37 @@
+# Installation and Bash Configuration
+
+In order to declare that your framework requires Perl, you should have an `install.sh`
+that contains at least
+
+    #!/bin/bash
+
+    fw_depends perl
+
+This installs the Perl interpreter and some basic modules (see Dependency Management).
+The `install.sh` file should then install any required perl modules or other supporting
+applications.
+
+Perl is installed in the `$IROOT` directory. Currently, the Perl interpreter
+used by the test is in version 5.18 family. It is highly recommended that
+you have a `bash_profile.sh` in your app's directory that contains at least
+
+    #!/bin/bash
+
+    export PERL_HOME=${IROOT}/perl-5.18
+    export PATH="$PERL_HOME/bin:$PATH"
+
+This will provide the `$PERL_HOME` path - should you need it - and 
+allow all apps installed by Perl to be used directly.
+
+# Dependency Management
+
+While installing Perl, the [`cpanm`](https://metacpan.org/pod/distribution/App-cpanminus/bin/cpanm)
+client is installed as well as the more advanced [`Carton`](https://metacpan.org/pod/Carton).
+Carton can be used to declare and use project specific dependencies with more fine grained control
+of versions and even pin the specific versions used during development.
+
+# Where to get help
+
+Perl advice can be found in #perl on freenode or on any number of channels on irc.perl.org.
+Frameworks might declare specific app maintainers in their app's README files.
+

+ 1 - 2
frameworks/Perl/mojolicious/README.md

@@ -1,8 +1,7 @@
 # Setup
 # Setup
 
 
 * Perl 5.16.3
 * Perl 5.16.3
-* MongoDB 2.4.9
-* Wrk 2.0
+* MongoDB 2.6
 
 
 # Requirements
 # Requirements
 
 

+ 13 - 9
frameworks/Perl/mojolicious/app.pl

@@ -10,14 +10,18 @@ plugin JSONConfig => {
   file => 'app.conf',
   file => 'app.conf',
   default => {
   default => {
     database_host => 'localhost',
     database_host => 'localhost',
-    workers => 8,
     hypnotoad => {
     hypnotoad => {
       graceful_timeout => 1,
       graceful_timeout => 1,
+      workers => 8,
     },
     },
+    hypnotoad_merge => {},
   },
   },
 };
 };
 
 
-app->config->{hypnotoad}{workers} = app->config->{workers};
+{
+  my $merge = app->config->{hypnotoad_merge};
+  @{app->config->{hypnotoad}}{keys %$merge} = values %$merge;
+}
 
 
 # Database connections
 # Database connections
 
 
@@ -32,19 +36,19 @@ helper render_json => sub { shift->render( data => encode_json(shift), format =>
 
 
 # Routes
 # Routes
 
 
-get '/json' => sub { shift->render_json({message => 'Hello, World!'}) };
+get '/json' => sub { shift->helpers->render_json({message => 'Hello, World!'}) };
 
 
-get '/db' => sub { shift->render_query(1, {single => 1}) };
+get '/db' => sub { shift->helpers->render_query(1, {single => 1}) };
 
 
 get '/queries' => sub {
 get '/queries' => sub {
   my $c = shift;
   my $c = shift;
-  $c->render_query(scalar $c->param('queries'));
+  $c->helpers->render_query(scalar $c->param('queries'));
 };
 };
 
 
 get '/fortunes' => sub {
 get '/fortunes' => sub {
   my $c = shift->render_later;
   my $c = shift->render_later;
   my $tx = $c->tx;
   my $tx = $c->tx;
-  $c->fortune->find->all(sub{
+  $c->helpers->fortune->find->all(sub{
     my ($cursor, $err, $docs) = @_;
     my ($cursor, $err, $docs) = @_;
     push @$docs, { _id => 0, message => 'Additional fortune added at request time.' };
     push @$docs, { _id => 0, message => 'Additional fortune added at request time.' };
     $c->render( fortunes => docs => $docs ) unless $tx->is_finished;
     $c->render( fortunes => docs => $docs ) unless $tx->is_finished;
@@ -53,7 +57,7 @@ get '/fortunes' => sub {
 
 
 get '/updates' => sub {
 get '/updates' => sub {
   my $c = shift;
   my $c = shift;
-  $c->render_query(scalar $c->param('queries'), {update => 1});
+  $c->helpers->render_query(scalar $c->param('queries'), {update => 1});
 };
 };
 
 
 get '/plaintext' => sub { shift->render( text => 'Hello, World!' ) };
 get '/plaintext' => sub { shift->render( text => 'Hello, World!' ) };
@@ -77,10 +81,10 @@ helper 'render_query' => sub {
   my $delay = Mojo::IOLoop->delay;
   my $delay = Mojo::IOLoop->delay;
   $delay->on(finish => sub{
   $delay->on(finish => sub{
     $r = $r->[0] if $args->{single};
     $r = $r->[0] if $args->{single};
-    $self->render_json($r) unless $tx->is_finished;
+    $self->helpers->render_json($r) unless $tx->is_finished;
   });
   });
 
 
-  my $world = $self->world;
+  my $world = $self->helpers->world;
 
 
   foreach (1 .. $q) {
   foreach (1 .. $q) {
     my $id = int rand 10_000;
     my $id = int rand 10_000;

+ 0 - 1
frameworks/Perl/mojolicious/bash_profile.sh

@@ -1,5 +1,4 @@
 #!/bin/bash
 #!/bin/bash
 
 
 export PERL_HOME=${IROOT}/perl-5.18
 export PERL_HOME=${IROOT}/perl-5.18
-
 export PATH="$PERL_HOME/bin:$PATH"
 export PATH="$PERL_HOME/bin:$PATH"

+ 1 - 1
frameworks/Perl/mojolicious/cpanfile

@@ -1,4 +1,4 @@
-requires 'Mojolicious', '>= 5.0';
+requires 'Mojolicious', '>= 5.29';
 requires 'Mango', '>= 1.0';
 requires 'Mango', '>= 1.0';
 requires 'JSON::XS';
 requires 'JSON::XS';
 requires 'EV';
 requires 'EV';

+ 7 - 7
frameworks/Perl/mojolicious/cpanfile.snapshot

@@ -16,10 +16,10 @@ DISTRIBUTIONS
       ExtUtils::MakeMaker 0
       ExtUtils::MakeMaker 0
       Types::Serialiser 0
       Types::Serialiser 0
       common::sense 0
       common::sense 0
-  Mango-1.05
-    pathname: S/SR/SRI/Mango-1.05.tar.gz
+  Mango-1.06
+    pathname: S/SR/SRI/Mango-1.06.tar.gz
     provides:
     provides:
-      Mango 1.05
+      Mango 1.06
       Mango::BSON undef
       Mango::BSON undef
       Mango::BSON::Binary undef
       Mango::BSON::Binary undef
       Mango::BSON::Code undef
       Mango::BSON::Code undef
@@ -39,9 +39,9 @@ DISTRIBUTIONS
       Mango::Protocol undef
       Mango::Protocol undef
     requirements:
     requirements:
       ExtUtils::MakeMaker 0
       ExtUtils::MakeMaker 0
-      Mojolicious 5.0
-  Mojolicious-5.28
-    pathname: S/SR/SRI/Mojolicious-5.28.tar.gz
+      Mojolicious 5.32
+  Mojolicious-5.32
+    pathname: S/SR/SRI/Mojolicious-5.32.tar.gz
     provides:
     provides:
       Mojo undef
       Mojo undef
       Mojo::Asset undef
       Mojo::Asset undef
@@ -104,7 +104,7 @@ DISTRIBUTIONS
       Mojo::UserAgent::Server undef
       Mojo::UserAgent::Server undef
       Mojo::UserAgent::Transactor undef
       Mojo::UserAgent::Transactor undef
       Mojo::Util undef
       Mojo::Util undef
-      Mojolicious 5.28
+      Mojolicious 5.32
       Mojolicious::Command undef
       Mojolicious::Command undef
       Mojolicious::Command::cgi undef
       Mojolicious::Command::cgi undef
       Mojolicious::Command::cpanify undef
       Mojolicious::Command::cpanify undef

+ 5 - 1
frameworks/Perl/mojolicious/setup.py

@@ -1,11 +1,15 @@
 import subprocess
 import subprocess
 import json
 import json
 import os
 import os
+import multiprocessing
 
 
 def start(args, logfile, errfile):
 def start(args, logfile, errfile):
   conf = { 
   conf = { 
     'database_host' : args.database_host,
     'database_host' : args.database_host,
-    'workers'       : args.max_threads,
+    'hypnotoad_merge' : {
+      'workers' : 2*multiprocessing.cpu_count(), 
+      # can use args.max_threads and args.max_concurrency to set
+    },
   }
   }
   with open(args.troot + '/app.conf', 'w') as f:
   with open(args.troot + '/app.conf', 'w') as f:
     f.write(json.dumps(conf))
     f.write(json.dumps(conf))