Skip to content

Commit

Permalink
reorganized config, set new secret, improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
reneeb committed May 3, 2012
1 parent af42c48 commit b8b0604
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
12 changes: 8 additions & 4 deletions pod_book/config.yml
@@ -1,10 +1,14 @@
---
loglevel: info
logpath_cpansearch: ./CpanSearch.log
caching_seconds: 864000
caching_name: cpan2ebook_webservice
logging:
level: info
path:
general: /home/ebook/perlybook.log
caching:
seconds: 864000
name: cpan2ebook_webservice
userblock_seconds: 2
tmp_dir: /home/ebook/tmp
reverse_proxy: 1
autocompletion_size: 12
optional_message: <br /><br /><br /><p><small>This website just came into the world. Please report any problems <a href='https://github.com/reneeb/cpan2ebook/issues'>here</a>.</small></p>
secret: mypassphrase
11 changes: 11 additions & 0 deletions pod_book/lib/PodBook.pm
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;

use Mojo::Base 'Mojolicious';
use Mojo::Log;

our $VERSION = 0.1;

Expand All @@ -28,6 +29,16 @@ sub startup {
$ENV{MOJO_REVERSE_PROXY} = 1;
}

# set log level
$self->app->log(
Mojo::Log->new(
level => ( $config->{logging}->{level} || 'debug' ),
path => ( $config->{logging}->{path}->{general} || $self->home . '/perlybook.log' ),
)
);

# set new passphrase
$self->app->secret( $config->{secret} || 'secret' );

# Routes
my $r = $self->routes;
Expand Down
27 changes: 13 additions & 14 deletions pod_book/lib/PodBook/CpanSearch.pm
Expand Up @@ -4,13 +4,13 @@ package PodBook::CpanSearch;
use Mojo::Base 'Mojolicious::Controller';

# the are the tools we need from CPAN
use Mojo::Log;
use Mojo::Headers;
use Mojo::UserAgent;
use Regexp::Common 'net';
use File::Temp 'tempfile';
use File::Slurp 'read_file';
use MetaCPAN::API;

use EPublisher;
use EPublisher::Source::Plugin::MetaCPAN;
use EPublisher::Target::Plugin::EPub;
Expand All @@ -28,18 +28,14 @@ sub form {

# lets load some values from the config file
my $config = $self->config;
my $loglevel = $config->{loglevel} || 'debug';
my $logpath = $config->{logpath_cpansearch} || './CpanSearch.log';
my $userblock_seconds = $config->{userblock_seconds};
my $cache_name = $config->{caching_name};
my $caching_seconds = $config->{caching_seconds};
my $cache_name = $config->{caching}->{name};
my $caching_seconds = $config->{caching}->{seconds};
my $tmp_dir = $config->{tmp_dir};
my $opt_msg = $config->{optional_message} || '<!-- -->';
my $listsize = $config->{autocompletion_size} || 10;
my $opt_msg = $config->{optional_message} || '<!-- -->';
my $listsize = $config->{autocompletion_size} || 10;

my $log = Mojo::Log->new( path => $logpath,
level => $loglevel,
);
my $log = $self->app->log;

# set size of autocompletion result list in the template (JavaScript)
if ( $listsize =~ /\D/ or $listsize > 100 ) {
Expand Down Expand Up @@ -89,6 +85,7 @@ sub form {
else {
# EXIT if unknown
$self->render( message => 'ERROR: Type of ebook unknown.' );
$self->app->log->warn( 'Type of ebook unknown' );
return;
}

Expand All @@ -98,6 +95,7 @@ sub form {
if ( !$module_name ) {
# EXIT if not matching
$self->render( message => 'ERROR: invalid chars in module name.' );
$self->app->log->info( 'invalid chars in module name: ' . $self->param( 'in_text' ) );
return;
}

Expand Down Expand Up @@ -148,6 +146,7 @@ sub form {
$self->render(
message => "ERROR: Can't reach MetaCPAN"
);
$self->app->log->error( 'Cannot reach MetaCPAN' );

# Exit
return;
Expand All @@ -160,16 +159,16 @@ sub form {
$self->render(
message => "ERROR: MetaCPAN does not answer as expected."
);
$self->app->log->error( 'MetaCPANs response looks unexpected' );

# Exit
return;
}

# extract the data we need from the json result
my $complete_release_name =
$autocomplete->json->{hits}->{hits}->[0]->{fields}->{release};
my $distribution =
$autocomplete->json->{hits}->{hits}->[0]->{fields}->{distribution};
my $fields = $autocomplete->json->{hits}->{hits}->[0]->{fields};
my $complete_release_name = $fields->{release};
my $distribution = $fields->{distribution};

# if this value is false, the module probably does not exist
unless ( $complete_release_name) {
Expand Down
2 changes: 1 addition & 1 deletion pod_book/script/cache_stats.pl
Expand Up @@ -17,7 +17,7 @@
$| = 1;

my $cache_dir = $yaml->[0]->{tmp_dir};
my $cache_namespace = $yaml->[0]->{caching_name};
my $cache_namespace = $yaml->[0]->{caching}->{name};

# load the cache
my $cache = CHI->new(
Expand Down
2 changes: 1 addition & 1 deletion pod_book/script/hourly.pl
Expand Up @@ -20,7 +20,7 @@
);

my $cache_dir = $config->[0]->{tmp_dir};
my $cache_namespace = $config->[0]->{caching_name};
my $cache_namespace = $config->[0]->{caching}->{name};

# load the cache
my $cache = CHI->new(
Expand Down

0 comments on commit b8b0604

Please sign in to comment.