diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14c56ab --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor_perl/** diff --git a/.perlcriticrc b/.perlcriticrc new file mode 100644 index 0000000..6aab75e --- /dev/null +++ b/.perlcriticrc @@ -0,0 +1,103 @@ +#!/usr/bin/env perlcritic +severity = 5 +verbose = 8 + +# minorify some of warnings that are not really critical +[-InputOutput::RequireCheckedClose] +# What can we handle in case of error? + +[-Modules::ProhibitExcessMainComplexity] +# Noone cares + +[-Subroutines::ProhibitExcessComplexity] +# Noone cares + +[-Subroutines::ProhibitExplicitReturnUndef] +# But it's very handy sometimes! + +[-ValuesAndExpressions::ProhibitMagicNumbers] +# this policy makes too much false positives + +[-RegularExpressions::RequireLineBoundaryMatching] +# We use /m as needed + +[-RegularExpressions::RequireExtendedFormatting] +# We do not use extended formatting of regex, they still not THAT complex + +[-RegularExpressions::RequireDotMatchAnything] +# huh? + +[-RegularExpressions::ProhibitEscapedMetacharacters] +# Looks like it pointless + +[-ControlStructures::ProhibitCascadingIfElse] +# I like long if..else chains + +[-ControlStructures::ProhibitPostfixControls] +# In short lines we can afford ourselves to use postfix controls +# but of course we should avoid such constructions in long lines. + +[-Subroutines::ProhibitSubroutinePrototypes] +# Contrary to Perl::Critic we consider prototypes as useful, even if +# the compile-time checks of Perl are not perfect, Perl may give some +# hints. + +[-CodeLayout::RequireTidyCode] +# Impossible to complete, because of on higher linting levels "## no critic..." +# require be per-case on same line where critique is, but tidy align them +# one line down. + +[-CodeLayout::ProhibitParensWithBuiltins] +# duh... + +[-ValuesAndExpressions::ProhibitEmptyQuotes] +# cause we consider following correct and useful: my $var = ''; +# the recommended use of q{} looks too complex: my $var = q{}; + +[-ValuesAndExpressions::ProhibitNoisyQuotes] +# Other people, other opinions: "," is better readable than qw(,) + +[-BuiltinFunctions::ProhibitSleepViaSelect] +# We do not wish to use too much external modules. +# select undef, undef, undef, 0.25; # actually is okay if you add comment that +# it is sleep for 0.25 seconds + +[-NamingConventions::Capitalization] +# duh... +# Noone cares, really + +[-ControlStructures::ProhibitUnlessBlocks] +# They should not be too complex - only one condition should be checked, +# that's all + +[-Miscellanea::ProhibitTies] +# Just allow it. It's very handy stuff and extremely simple and safe enough to use. + +[-ValuesAndExpressions::RequireNumberSeparators] +# Not really + +[-InputOutput::RequireBracedFileHandleWithPrint] +# We prefer not to use braced file handles + +[-Documentation::PodSpelling] +# It doesn't help, but emits annoying errors + +[Documentation::RequirePodSections] +# Considering this as "soft" requirement. For modules that is (or will be) +# stand-alone libs well formed documentation is highly desired. +lib_sections = NAME | VERSION | DESCRIPTION | AUTHOR | LICENSE AND COPYRIGHT + +[-ErrorHandling::RequireCheckingReturnValueOfEval] +# In this app eval is not critical to error, so there is no need to check for it + +[-InputOutput::RequireBriefOpen] +# Yes, i do! + +[-InputOutput::RequireCheckedSyscalls] +# What can go wrong in "say"? what and how should i handle in this case? + +[-ControlStructures::ProhibitDeepNests] +# Oh, really? Maybe you know better solution? + +[-Variables::ProhibitPunctuationVars] +# I don't want use English here \ No newline at end of file diff --git a/README.md b/README.md index 2b59a8e..c3b0a67 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ видосик во временный каталог, отдаёт видосик клиенту. Есть встроенное ограничение на размер файла в 10Мб. -N.B. Файлы из временного каталога автоматически не вычищаются. +N.B. Файлы из временного каталога автоматически не вычищаются. Получается +своего рода "перманентный" кэш. ## Как это запустить? diff --git a/cpanfile b/cpanfile index 227c3eb..a040f62 100644 --- a/cpanfile +++ b/cpanfile @@ -1,3 +1,4 @@ -require HTTP::Tiny; -require URI::URL; -require URI::Escape; +requires 'HTTP::Tiny'; +requires 'URI::URL'; +requires 'URI::Escape'; +requires 'Plack::Util'; diff --git a/joyproxy.pm b/joyproxy.pm index 4cd4973..9e42d86 100644 --- a/joyproxy.pm +++ b/joyproxy.pm @@ -36,11 +36,11 @@ sub joyproxy ($) { if (defined $readlen) { if ($readlen != $filesize) { - warn "Unable to read $file readlen does not match filesize: $readlen vs $filesize"; + carp "Unable to read $file readlen does not match filesize: $readlen vs $filesize"; return ('500', 'text/plain', "Unable to read file in temporary location\n"); } } else { - warn "Unable to read $file: $!"; + carp "Unable to read $file: $!"; return ('500', 'text/plain', "Unable to read file in temporary location: $!\n"); } @@ -130,7 +130,7 @@ sub __dlfunc($) { my $url = shift; unless (-d '/tmp/joyproxy') { - warn 'no /tmp/joyproxy'; + carp 'no /tmp/joyproxy'; unless (mkdir '/tmp/joyproxy') { return (undef, undef); @@ -138,7 +138,7 @@ sub __dlfunc($) { } my @explodedurl = split /\//msx, $url; - my $file = $explodedurl[$#explodedurl]; + my $file = $explodedurl[$#explodedurl]; ## no critic (Variables::RequireNegativeIndices) $#explodedurl = -1; undef @explodedurl; $file = '/tmp/joyproxy/' . $file; $url = __urlencode ($url); diff --git a/joyproxy.psgi b/joyproxy.psgi index 2b6ab45..b6224fb 100644 --- a/joyproxy.psgi +++ b/joyproxy.psgi @@ -1,3 +1,5 @@ +#!/usr/bin/perl + use 5.018; use strict; use warnings; diff --git a/joyproxy.yaml b/joyproxy.yaml new file mode 100644 index 0000000..249980e --- /dev/null +++ b/joyproxy.yaml @@ -0,0 +1,17 @@ +uwsgi: + http-socket: 127.0.0.1:3081 + socket-protocol: http + so-keepalive: 0 + logformat: %(var.REMOTE_ADDR) %(var.REQUEST_METHOD) %(var.REQUEST_URI) %(status) + processes: 1 + need-app: true + log-reopen: yes + reload-mercy: 5 + buffer-size: 32768 + die-on-term: true + pidfile: /run/joyproxy/joyproxy.pid + logto: /var/log/joyproxy/joyproxy.log + plugins: psgi + chdir: /var/lib/joyproxy + psgi: /var/lib/joyproxy/joyproxy.psgi + perl-local-lib: /var/lib/joyproxy/vendor_perl \ No newline at end of file