StaticShare.pm

filter: Statementstmt 68.0% 98 / 144 Branchbran 26.7% 15 / 56 Conditioncond 12.3% 9 / 73 MC/DCmcdc 0.0% 0 / 35 Subroutinesub 61.5% 24 / 39 Podpod 33.3% 1 / 3 totaltotal 42.0% 147 / 350 CC 56 SCAR 35.4
CC
56
Cov
45%
__ANON__
132.0
i18n
52.2
register
48.1
CRAP 34.5
« StaticShare/Controller.pm ↑ Summary PODRenderer.pm »
1 package Mojolicious::Plugin::StaticShare;
2 2 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Mojo::File qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Mojolicious::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Mojo::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Mojo::Util;# qw(decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 my $PKG = __PACKAGE__;
10  
11 2 has qw(app) => undef, weak => 1;
12 2 has qw(config);# => undef, weak => 1;
13 1 ▶has root_url => sub { Mojo::Path->new(shift->config->{root_url})->leading_slash(1)->trailing_slash(1) };
Subroutine __ANON__: called CC=1 SCAR=0.0
14 1 ▶has root_dir => sub { Mojo::Path->new(shift->config->{root_dir} // '.')->trailing_slash(1) };
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition50%1/2
+(shift())->config->{"root_dir"} // "."
l!l
01
MC/DC0%0/1
+(shift())->config->{"root_dir"} // "."
+(shift())->config->{"root_dir"}
Truth table50%1/2
A
A= +(shift())->config->{"root_dir"}
Aresult
11
00
15 1 ▶has host => sub { shift->config->{host} };
Subroutine __ANON__: called CC=1 SCAR=0.0
16 1 ▶has admin_pass => sub { shift->config->{admin_pass} };
Subroutine __ANON__: called CC=1 SCAR=0.0
17 1 ▶has access => sub { shift->config->{access} };
Subroutine __ANON__: called CC=1 SCAR=0.0
18 1 ▶has public_uploads => sub { !! shift->config->{public_uploads} };
Subroutine __ANON__: called CC=1 SCAR=0.0
19 1 ▶has render_dir => sub { shift->config->{render_dir} };
Subroutine __ANON__: called CC=1 SCAR=0.0
20 1 ▶has dir_index => sub { shift->config->{dir_index} // [qw(README.md INDEX.md README.pod INDEX.pod)] };
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition50%1/2
+(shift())->config->{"dir_index"} // ["README.md", "INDEX.md", "README.pod", "INDEX.pod"]
l!l
01
MC/DC0%0/1
+(shift())->config->{"dir_index"} // ["README.md", "INDEX.md", "README.pod", "INDEX.pod"]
+(shift())->config->{"dir_index"}
Truth table50%1/2
A
A= +(shift())->config->{"dir_index"}
Aresult
11
00
21 0 ▶has render_pod => sub { shift->config->{render_pod} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
22 0 ▶has render_markdown => sub { shift->config->{render_markdown} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
23 0 ▶has markdown_pkg => sub { shift->config->{markdown_pkg} // 'Text::Markdown::Hoedown' };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/2
+(shift())->config->{"markdown_pkg"} // "Text::Markdown::Hoedown"
l!l
00
MC/DC0%0/1
+(shift())->config->{"markdown_pkg"} // "Text::Markdown::Hoedown"
+(shift())->config->{"markdown_pkg"}
Truth table0%0/2
A
A= +(shift())->config->{"markdown_pkg"}
Aresult
11
00
24 1 ▶has templates_dir => sub { shift->config->{templates_dir} };
Subroutine __ANON__: called CC=1 SCAR=0.0
25 0 ▶has markdown => sub {# parser object
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 __internal__::Markdown->new(shift->markdown_pkg);
27 2 };
28 1 ▶has re_markdown => sub { qr{[.]m(?:d(?:own)?|kdn?|arkdown)$}i };
Subroutine __ANON__: called CC=1 SCAR=0.0
29 1 ▶has re_pod => sub { qr{[.]p(?:od|m|l)$} };
Subroutine __ANON__: called CC=1 SCAR=0.0
30 0 ▶has re_html => sub { qr{[.]html?$} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
31 0 ▶has mime => sub { Mojolicious::Types->new };
Subroutine __ANON__: not called CC=1 SCAR=1.2
32 1 ▶has max_upload_size => sub { shift->config->{max_upload_size} };
Subroutine __ANON__: called CC=1 SCAR=0.0
33 #separate routes store for matching without conflicts
34 0 ▶has routes => sub { Mojolicious::Routes->new }; # для max_upload_size
Subroutine __ANON__: not called CC=1 SCAR=1.2
35 1 ▶has routes_names => sub {# тоже для max_upload_size
Subroutine __ANON__: called CC=1 SCAR=0.0
36 1 my $self = shift;
37 1 return [$self." ROOT GET (#1)", $self." PATH GET (#2)", $self." ROOT POST (#3)", $self." PATH POST (#4)"];
38 2 };
39 0 ▶has debug => sub { shift->config->{debug} // $ENV{StaticShare_DEBUG} };
Subroutine __ANON__: not called CC=2 SCAR=14.0
Condition0%0/3
+(shift())->config->{"debug"} // $ENV{"StaticShare_DEBUG"}
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->config->{"debug"} // $ENV{"StaticShare_DEBUG"}
+(shift())->config->{"debug"} $ENV{"StaticShare_DEBUG"}
Truth table0%0/3
A // B
A= +(shift())->config->{"debug"}B= $ENV{"StaticShare_DEBUG"}
ABresult
1X1
011
000
40  
41  
42 1 ▶sub register {# none magic
Subroutine register: called CC=18 SCAR=38.7
Pod documented
43 1 my ($self, $app, $args) = @_;
44 1 $self->config($args);
45 1 $self->app($app);
46
47 1 my $push_class = "$PKG\::Templates";
48 1 my $push_path = path(__FILE__)->sibling('StaticShare')->child('static');
49
50 require Mojolicious::Plugin::StaticShare::Templates
51 1 ▶ and push @{$app->renderer->classes}, grep($_ eq $push_class, @{$app->renderer->classes}) ? () : $push_class
Branch: 1 branch
BranchTrueFalseTotal
grep(($_ eq $push_class), @{$app->renderer->classes;}) ? : 0 1 1
52 1 ▶ and push @{$app->static->paths}, grep($_ eq $push_path, @{$app->static->paths}) ? () : $push_path
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->render_dir // "") eq 0 and ($self->render_markdown // "") eq 0 1 0 1
grep(($_ eq $push_path), @{$app->static->paths;}) ? : 0 1 1
Condition31%5/16
($self->render_dir // '') eq 0 && ($self->render_markdown // '') eq 0 || require Mojolicious::Plugin::StaticShare::Templates && push(@{$app->renderer->classes;}, grep(($_ eq $push_class), @{$app->renderer->classes;}) ? () : $push_class) && push(@{$app->static->paths;}, grep(($_ eq $push_path), @{$app->static->paths;}) ? () : $push_path)
l!l&&r!l&&!r
010
($self->render_dir // "") eq 0 and ($self->render_markdown // "") eq 0
!ll&&!rl&&r
100
$self->render_dir // ""
l!l
01
$self->render_markdown // ""
l!l
00
require Mojolicious::Plugin::StaticShare::Templates and push @{$app->renderer->classes;}, grep(($_ eq $push_class), @{$app->renderer->classes;}) ? () : $push_class and push @{$app->static->paths;}, grep(($_ eq $push_path), @{$app->static->paths;}) ? () : $push_path
!ll&&!rl&&r
010
require Mojolicious::Plugin::StaticShare::Templates and push @{$app->renderer->classes;}, grep(($_ eq $push_class), @{$app->renderer->classes;}) ? () : $push_class
!ll&&!rl&&r
001
MC/DC0%0/5
($self->render_dir // '') eq 0 && ($self->render_markdown // '') eq 0 || require Mojolicious::Plugin::StaticShare::Templates && push(@{$app->renderer->classes;}, grep(($_ eq $push_class), @{$app->renderer->classes;}) ? () : $push_class) && push(@{$app->static->paths;}, grep(($_ eq $push_path), @{$app->static->paths;}) ? () : $push_path)
$self->render_dir $self->render_markdown require Mojolicious::Plugin::StaticShare::Templates push @{$app->renderer->classes;}, grep(($_ eq $push_class), @{$app->renderer->classes;}) ? () : $push_class push @{$app->static->paths;}, grep(($_ eq $push_path), @{$app->static->paths;}) ? () : $push_path
Truth table0%0/9
A and B || C and D and E
A= $self->render_dirB= $self->render_markdownC= require Mojolicious::Plugin::StaticShare::TemplatesD= push @{$app->renderer->classes;}, grep(($_ eq $push_class), @{$app->renderer->classes;}) ? () : $push_classE= push @{$app->static->paths;}, grep(($_ eq $push_path), @{$app->static->paths;}) ? () : $push_path
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
53 unless ($self->render_dir // '') eq 0
54 && ($self->render_markdown // '') eq 0;
55 0 ▶ push @{$app->renderer->paths}, ref $self->templates_dir ? @{$self->templates_dir} : $self->templates_dir
Branch: 2 branches
BranchTrueFalseTotal
if $self->templates_dir 0 1 1
ref $self->templates_dir ? : 0 0 0
56 if $self->templates_dir;
57
58 # ROUTING 4 routes
59 1 my $route = $self->root_url->clone->merge('*pth');#"$args->{root_url}/*pth";
60 1 my $names = $self->routes_names;
61 1 $self->_make_route(routes => $app->routes, action => 'get', path => $self->root_url->to_route, name => $names->[0], pth => '', host => $self->host, )
62 ->_make_route(routes => $app->routes, action => 'get', path => $route->to_route, name => $names->[1], host => $self->host,)
63 ->_make_route(routes => $app->routes, action => 'post', path => $self->root_url->to_route, name => $names->[2], pth => '', host => $self->host,)
64 ->_make_route(routes => $app->routes, action => 'post', path => $route->to_route, name => $names->[3], host => $self->host,);
65 #~ $r->get($self->root_url->to_route)->to(namespace=>$PKG, controller=>"Controller", action=>'get', pth=>'', plugin=>$self, )->name($names->[0]);#$PKG
66 #~ $r->get($route->to_route)->to(namespace=>$PKG, controller=>"Controller", action=>'get', plugin=>$self, )->name($names->[1]);#;
67 #~ $r->post($self->root_url->to_route)->to(namespace=>$PKG, controller=>"Controller", action=>'post', pth=>'', plugin=>$self, )->name($names->[2]);#->name("$PKG ROOT POST");
68 #~ $r->post($route->to_route)->to(namespace=>$PKG, controller=>"Controller", action=>'post', plugin=>$self, )->name($names->[3]);#;
69
70
71 # only POST uploads
72 1 ▶ $self->_make_route(routes => $self->routes, action => 'post', path => $self->root_url->to_route, name => $names->[2], pth => '')# без host!
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->max_upload_size 0 1 1
73 ->_make_route(routes => $self->routes, action => 'post', path => $route->to_route, name => $names->[3])
74 if defined $self->max_upload_size;
75
76 path($self->config->{root_dir})->make_path
77 1 ▶ unless !$self->config->{root_dir} || -e $self->config->{root_dir};
Branch: 1 branch
BranchTrueFalseTotal
unless not $self->config->{"root_dir"} or -e $self->config->{"root_dir"} 0 1 1
Condition33%1/3
not $self->config->{"root_dir"} or -e $self->config->{"root_dir"}
l!l&&r!l&&!r
100
MC/DC0%0/2
not $self->config->{"root_dir"} or -e $self->config->{"root_dir"}
not $self->config->{"root_dir"} -e $self->config->{"root_dir"}
Truth table33%1/3
not(A) or B
A= not $self->config->{"root_dir"}B= -e $self->config->{"root_dir"}
ABresult
1X1
011
000
78  
79 1 $app->helper(i18n => \&i18n);
80 #~ $app->helper(StaticShareIsAdmin => sub { $self->is_admin(@_) });
81
82 #POD
83 $self->app->plugin(PODRenderer => {no_perldoc => 1})
84 1 ▶ unless $self->app->renderer->helpers->{'pod_to_html'} && ($self->render_pod // '') eq 0 ;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->app->renderer->helpers->{"pod_to_html"} and ($self->render_pod // "") eq 0 1 0 1
Condition20%1/5
$self->app->renderer->helpers->{"pod_to_html"} and ($self->render_pod // "") eq 0
!ll&&!rl&&r
100
$self->render_pod // ""
l!l
00
MC/DC0%0/2
$self->app->renderer->helpers->{"pod_to_html"} and ($self->render_pod // "") eq 0
$self->app->renderer->helpers->{"pod_to_html"} $self->render_pod
Truth table33%1/3
A and B
A= $self->app->renderer->helpers->{"pod_to_html"}B= $self->render_pod
ABresult
0X0
100
111
85
86 # PATCH EMIT CHUNK
87 1 ▶ $self->_hook_chunk()
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->max_upload_size 0 1 1
88 if defined $self->max_upload_size;
89
90 1 return ($app, $self);
91 }
92  
93 4 ▶sub _make_route {
Subroutine _make_route: called CC=4 SCAR=14.0
94 4 my ($self) = shift;
95 4 ▶ my $arg = ref $_[0] ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 4 4
96 4 weaken $self;
97 4 my $action = $arg->{action};
98 4 my $r = $arg->{routes}->$action($arg->{path});
99 4 ▶ $r->to(namespace=>$PKG, controller=>"Controller", action=>$arg->{action}, defined $arg->{pth} ? (pth=>$arg->{pth}) : (), plugin=>$self, );
Branch: 1 branch
BranchTrueFalseTotal
defined $arg->{'pth'} ? : 2 2 4
100 4 $r->name($arg->{name});
101 $r->requires(host => $arg->{host})
102 4 ▶ if $arg->{host};
Branch: 1 branch
BranchTrueFalseTotal
if $arg->{"host"} 0 4 4
103 4 return $self;
104 }
105  
106 2 my %loc = (
107 'ru-ru'=>{
108 'Not found'=>"Не найдено",
109 'Error on path'=>"Ошибка в",
110 'Error'=>"Ошибка",
111 'Permission denied'=>"Нет доступа",
112 'Cant open directory'=>"Нет доступа в папку",
113 'Share'=>'Обзор',
114 'Edit'=>'Редактировать',
115 'Index of'=>'Содержание',
116 'Dirs'=>'Папки',
117 'Files'=>'Файлы',
118 'Name'=>'Название файла',
119 'Size'=>'Размер',
120 'Last Modified'=>'Дата изменения',
121 'Up'=>'Выше',
122 'Down'=>'Ниже',
123 'Add uploads'=>'Добавить файлы',
124 'Add dir'=>'Добавить папку',
125 'root'=>"корень",
126 'Uploading'=>'Загружается',
127 'file is too big'=>'слишком большой файл',
128 'path is not directory'=>"нет такого каталога/папки",
129 'file already exists' => "такой файл уже есть",
130 'new dir name'=>"имя новой папки",
131 'Confirm to delete these files'=>"Подтвердите удаление этих файлов",
132 'Confirm to delete these dirs'=>"Подтвердите удаление этих папок",
133 'I AM SURE'=>"ДА",
134 'Save'=> 'Сохранить',
135 'Success saved' => "Успешно сохранено",
136 'you cant delete'=>"Удаление запрещено, обратитесь к админу",
137 'you cant upload'=>"Запрещено, обратитесь к админу",
138 'you cant create dir'=>"Создание папки запрещено, обратитесь к админу",
139 'you cant rename'=>"Переименование запрещено, обратитесь к админу",
140 'you cant edit' => "Редактирование запрещено, обратитесь к админу",
141 },
142 );
143 15 ▶sub i18n {# helper
Subroutine i18n: called CC=10 SCAR=39.5
Pod undocumented
144 15 my ($c, $str, $lang) = @_;
145 #~ $lang //= $c->stash('language');
146 15 ▶ return $str
Branch: 1 branch
BranchTrueFalseTotal
unless $c->stash("language") 0 15 15
147 unless $c->stash('language');
148 15 my $loc;
149 15 for ($c->stash('language')->languages) {
150 15 ▶ return $str
Branch: 1 branch
BranchTrueFalseTotal
if /en/u 15 0 15
151 if /en/;
152 0 ▶ $loc = $loc{$_} || $loc{lc $_} || $loc{lc "$_-$_"}
Branch: 1 branch
BranchTrueFalseTotal
$loc = $loc{$_} || $loc{lc $_} || $loc{lc "$_-$_"} and last 0 0 0
Condition0%0/6
$loc{$_} || $loc{lc $_} || $loc{lc "$_-$_"}
l!l&&r!l&&!r
000
$loc{$_} or $loc{lc $_}
l!l&&r!l&&!r
000
MC/DC0%0/3
$loc{$_} || $loc{lc $_} || $loc{lc "$_-$_"}
$loc{$_} $loc{lc $_} $loc{lc "$_-$_"}
Truth table0%0/4
A or B || C
A= $loc{$_}B= $loc{lc $_}C= $loc{lc "$_-$_"}
ABCresult
1XX1
01X1
0011
0000
153 and last;
154 }
155 0 ▶ return $loc->{$str} || $loc->{lc $str} || $str
Branch: 1 branch
BranchTrueFalseTotal
if $loc 0 0 0
Condition0%0/6
$loc->{$str} || $$loc{lc $str} || $str
l!l&&r!l&&!r
000
$loc->{$str} or $$loc{lc $str}
l!l&&r!l&&!r
000
MC/DC0%0/3
$loc->{$str} || $$loc{lc $str} || $str
$loc->{$str} $$loc{lc $str} $str
Truth table0%0/4
A or B || C
A= $loc->{$str}B= $$loc{lc $str}C= $str
ABCresult
1XX1
01X1
0011
0000
156 if $loc;
157 0 return $str;
158 }
159  
160 1 ▶sub is_admin {# as helper
Subroutine is_admin: called CC=5 SCAR=28.8
Pod undocumented
161 1 my ($self, $c) = @_;
162 return
163 1 ▶ unless my $pass = $self->admin_pass;
Branch: 1 branch
BranchTrueFalseTotal
unless my $pass = $self->admin_pass 1 0 1
164 0 my $sess = $c->session;
165 0 ▶ $sess->{StaticShare}{admin} = 1
Branch: 1 branch
BranchTrueFalseTotal
if $c->param("admin") and $c->param("admin") eq $pass 0 0 0
Condition0%0/3
$c->param("admin") and $c->param("admin") eq $pass
!ll&&!rl&&r
000
MC/DC0%0/2
$c->param("admin") and $c->param("admin") eq $pass
$c->param("admin") $c->param("admin") eq $pass
Truth table0%0/3
A and B
A= $c->param("admin")B= $c->param("admin") eq $pass
ABresult
0X0
100
111
166 if $c->param('admin') && $c->param('admin') eq $pass;
167 0 ▶ return $sess->{StaticShare} && $sess->{StaticShare}{admin};
Condition0%0/3
$sess->{'StaticShare'} && $sess->{'StaticShare'}{'admin'}
!ll&&!rl&&r
000
MC/DC0%0/2
$sess->{'StaticShare'} && $sess->{'StaticShare'}{'admin'}
$sess->{'StaticShare'} $sess->{'StaticShare'}{'admin'}
Truth table0%0/3
A && B
A= $sess->{'StaticShare'}B= $sess->{'StaticShare'}{'admin'}
ABresult
0X0
100
111
168 }
169  
170 2 my $patched;
171 0 ▶sub _hook_chunk {
Subroutine _hook_chunk: not called CC=2 SCAR=17.9
172 0 my $self = shift;
173
174 0 ▶ _patch_emit_chunk() unless $patched++;
Branch: 1 branch
BranchTrueFalseTotal
unless $patched++ 0 0 0
175
176 0 weaken $self;
177 0 ▶ $self->app->hook(after_build_tx => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
178 0 my ($tx, $app) = @_;
179 0 ▶ $tx->once('chunk'=>sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
180 0 my ($tx, $chunk) = @_;
181 0 ▶ return unless $tx->req->method =~ /PUT|POST/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx->req->method =~ /PUT|POST/u 0 0 0
182 0 my $url = $tx->req->url->to_abs;
183 0 my $match = Mojolicious::Routes::Match->new(root => $self->routes);
184 #~ weaken $tx;
185 #~ weaken $app;
186 #~ Mojolicious::Controller->new(app=>$app, tx=>$tx)
187 0 my $host = $self->host;
188 0 $match->find(undef, {method => $tx->req->method, path => $url->path->to_route});# websocket => $ws
189 0 ▶ $app->log->debug("TX ONCE CHUNK check path: [".$url->path->to_route."]",
Branch: 2 branches
BranchTrueFalseTotal
if $self->debug 0 0 0
$host ? : 0 0 0
Condition0%0/5
$match->endpoint && $match->endpoint->name || 'none'
l!l
00
$match->endpoint and $match->endpoint->name
!ll&&!rl&&r
000
MC/DC0%0/2
$match->endpoint && $match->endpoint->name || 'none'
$match->endpoint $match->endpoint->name
Truth table0%0/3
A and B
A= $match->endpointB= $match->endpoint->name
ABresult
111
0X0
100
190 "match route: ". (($match->endpoint && $match->endpoint->name) || 'none'),
191 $host ? ("match host: ". $tx->req->headers->host =~ /$host/) : () #, Mojo::Util::dumper($url)
192 ) if $self->debug;
193 0 ▶ my $route = $match->endpoint
Condition0%0/2
$match->endpoint || (return)
l!l
00
MC/DC0%0/1
$match->endpoint || (return)
$match->endpoint
Truth table0%0/2
A
A= $match->endpoint
Aresult
11
00
194 || return;
195
196 0 ▶ $tx->req->max_message_size($self->max_upload_size)
Branch: 1 branch
BranchTrueFalseTotal
if $route->name eq $self->routes_names->[2] || $route->name eq $self->routes_names->[3] and $host and $tx->req->headers->host =~ /$host/u 0 0 0
Condition0%0/9
$route->name eq $self->routes_names->[2] || $route->name eq $self->routes_names->[3] and $host and $tx->req->headers->host =~ /$host/u
!ll&&!rl&&r
000
$route->name eq $self->routes_names->[2] || $route->name eq $self->routes_names->[3] and $host
!ll&&!rl&&r
000
$route->name eq $self->routes_names->[2] or $route->name eq $self->routes_names->[3]
l!l&&r!l&&!r
000
MC/DC0%0/4
$route->name eq $self->routes_names->[2] || $route->name eq $self->routes_names->[3] and $host and $tx->req->headers->host =~ /$host/u
$route->name eq $self->routes_names->[2] $route->name eq $self->routes_names->[3] $host $tx->req->headers->host =~ /$host/u
Truth table0%0/7
A or B and C and D
A= $route->name eq $self->routes_names->[2]B= $route->name eq $self->routes_names->[3]C= $hostD= $tx->req->headers->host =~ /$host/u
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
197 if (($route->name eq $self->routes_names->[2]) || ($route->name eq $self->routes_names->[3]))
198 && $host && $tx->req->headers->host =~ /$host/; # Хост ловится только так, в $url нет(
199 # TODO admin session
200
201 0 });
202 0 });
203
204 }
205  
206 0 ▶sub _patch_emit_chunk {
Subroutine _patch_emit_chunk: not called CC=1 SCAR=6.9
207
208 0 ▶ Mojo::Util::monkey_patch 'Mojo::Transaction::HTTP', 'server_read' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
209 0 my ($self, $chunk) = @_;
210
211 0 $self->emit('chunk before req parse'=>$chunk);### только одна строка патча этот эмит
212
213 # Parse request
214 0 my $req = $self->req;
215 0 ▶ $req->parse($chunk) unless $req->error;
Branch: 1 branch
BranchTrueFalseTotal
unless $req->error 0 0 0
216
217 0 $self->emit('chunk'=>$chunk);### только одна строка патча этот эмит
218
219 # Generate response
220 0 ▶ $self->emit('request') if $req->is_finished && !$self->{handled}++;
Branch: 1 branch
BranchTrueFalseTotal
if $req->is_finished and not $self->{"handled"}++ 0 0 0
Condition0%0/3
$req->is_finished and not $self->{"handled"}++
!ll&&!rl&&r
000
MC/DC0%0/2
$req->is_finished and not $self->{"handled"}++
$req->is_finished not $self->{"handled"}++
Truth table0%0/3
A and not(B)
A= $req->is_finishedB= not $self->{"handled"}++
ABresult
0X0
100
111
221
222 0 };
223
224 }
225  
226 2 our $VERSION = '0.075';
227  
228 ##############################################
229 package __internal__::Markdown;
230 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
231 0 my $class = shift;
232 0 my $pkg = shift;
233 return
234 0 ▶ unless eval "require $pkg; 1";#
Branch: 1 branch
BranchTrueFalseTotal
unless eval "require $pkg; 1" 0 0 0
235 #~ $pkg->import
236 #~ if $pkg->can('import');
237 0 ▶ return $pkg->new()
Branch: 1 branch
BranchTrueFalseTotal
if $pkg->can("new") and $pkg->can("parse") 0 0 0
Condition0%0/3
$pkg->can("new") and $pkg->can("parse")
!ll&&!rl&&r
000
MC/DC0%0/2
$pkg->can("new") and $pkg->can("parse")
$pkg->can("new") $pkg->can("parse")
Truth table0%0/3
A and B
A= $pkg->can("new")B= $pkg->can("parse")
ABresult
0X0
100
111
238 if $pkg->can('new') && $pkg->can('parse');
239 return
240 0 ▶ unless $pkg->can('markdown');
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg->can("markdown") 0 0 0
241 0 bless {pkg=>$pkg} => $class;
242 }
243  
244 0 ▶sub parse { my $self = shift; no strict 'refs'; ($self->{pkg}.'::markdown')->(@_); }
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine parse: not called CC=1 SCAR=0.6
245  
246  
247 =pod
248  
249 =encoding utf8
250  
251 Доброго всем
252  
253 =head1 Mojolicious::Plugin::StaticShare
254  
255 ¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !
256  
257 =head1 NAME
258  
259 Mojolicious::Plugin::StaticShare - browse, upload, copy, move, delete, edit, rename static files and dirs.
260  
261 =head1 VERSION
262  
263 0.075
264  
265 =head1 SYNOPSIS
266  
267 # Mojolicious
268 $app->plugin('StaticShare', <options>);
269  
270 # Mojolicious::Lite
271 plugin 'StaticShare', <options>;
272
273 # oneliner
274 $ perl -MMojolicious::Lite -E 'plugin("StaticShare", root_url=>"/my/share",)->secrets([rand])->start' daemon
275  
276 L</MULTI-PLUGIN> also.
277  
278 =head1 DESCRIPTION
279  
280 This plugin allow to share static files/dirs/markdown and has public and admin functionality:
281  
282 =head2 Public interface
283  
284 Can browse and upload files if name not exists.
285  
286 =head2 Admin interface
287  
288 Can copy, move, delete, rename and edit content of files/dirs.
289  
290 Append param C<< admin=<admin_pass> option >> to any url inside B<root_url> requests (see below).
291  
292 =head1 OPTIONS
293  
294 =head2 host
295  
296 host => 'local', # mean =~ /local/
297 host => qr/fobar\.com$/,
298  
299 String or regexp C< qr// >. Allow routing for given host.
300  
301 =head2 root_dir
302  
303 Absolute or relative file system path root directory. Defaults to '.'.
304  
305 root_dir => '/mnt/usb',
306 root_dir => 'foo',
307  
308 =head2 root_url
309  
310 This prefix to url path. Defaults to '/'.
311  
312 root_url => '/', # mean route '/*pth'
313 root_url => '', # mean also route '/*pth'
314 root_url => '/my/share', # mean route '/my/share/*pth'
315  
316 See L<Mojolicious::Guides::Routing#Wildcard-placeholders>.
317  
318 =head2 admin_pass
319  
320 Admin password (be sure https) for admin tasks. None defaults.
321  
322 admin_pass => '$%^!!9nes--', #
323  
324 Sign into admin interface by pass param B<admin> to shares paths C< https://<...>?admin=$%^!!9nes-- >
325  
326 =head2 render_dir
327  
328 Template path, format, handler, etc which render directory index. Defaults to builtin things.
329  
330 render_dir => 'foo/dir_index',
331 render_dir => {template => 'foo/my_directory_index', foo=>...},
332 # Disable directory index rendering
333 render_dir => 0,
334  
335 =head3 Usefull stash variables
336  
337 Plugin make any stash variables for rendering: C<pth>, C<url_path>, C<file_path>, C<language>, C<dirs>, C<files>, C<index>
338  
339 =head4 pth
340  
341 Path of request exept C<root_url> option, as L<Mojo::Path> object.
342  
343 =head4 url_path
344  
345 Path of request with C<root_url> option, as L<Mojo::Path> object.
346  
347 =head4 language
348  
349 Req header AcceptLanguage as L<HTTP::AcceptLanguage> object.
350  
351 =head4 dirs
352  
353 List of scalars dirnames. Not sorted.
354  
355 =head4 files
356  
357 List of hashrefs (C<name, size, mtime> keys) files. Not sorted.
358  
359 =head4 index
360  
361 Filename for markdown or pod rendering in page below the column dirs and column files.
362  
363 =head2 templates_dir
364  
365 String or arrayref strings. Simply C<< push @{$app->renderer->paths}, <templates_dir>; >>. None defaults.
366  
367 Mainly needs for layouting markdown. When you set this option then you can define layout inside markdown/pod files like syntax:
368  
369 % layouts/foo.html.ep
370 # Foo header
371  
372 =head2 render_markdown
373  
374 Same as B<render_dir> but for markdown files. Defaults to builtin things.
375  
376 render_markdown => 'foo/markdown',
377 render_markdown => {template => 'foo/markdown', foo=>...},
378 # Disable markdown rendering
379 render_markdown => 0,
380  
381 =head2 markdown_pkg
382  
383 Module name for render markdown. Must contains sub C<markdown($str)> or method C<parse($str)>. Defaults to L<Text::Markdown::Hoedown>.
384  
385 markdown_pkg => 'Foo::Markup';
386  
387 Does not need to install if C<< render_markdown => 0 >> or never render md files.
388  
389 =head2 render_pod
390  
391 Template path, format, handler, etc which render pod files. Defaults to builtin things.
392  
393 render_pod=>'foo/pod',
394 render_pod => {template => 'foo/pod', layout=>'pod', foo=>...},
395 # Disable pod rendering
396 render_pod => 0,
397  
398 =head2 dir_index
399  
400 Arrayref to match files to include to directory index page. Defaults to C<< [qw(README.md INDEX.md README.pod INDEX.pod)] >>.
401  
402 dir_index => [qw(DIR.md)],
403 dir_index => 0, # disable include markdown to index dir page
404  
405 =head2 public_uploads
406  
407 Boolean to disable/enable uploads for public users. Defaults to undef (disable).
408  
409 public_uploads=>1, # enable
410  
411 =head2 max_upload_size
412  
413 max_upload_size=>0, # unlimited POST
414  
415 Numeric value limiting uploads size for route. Defaults to Mojolicious setting.
416 EXPIRIMENTAL patching of the L<Mojo::Transaction::HTTP#server_read>
417 for emit B<chunk> event.
418  
419 See also L<Mojolicious#max_request_size>, L<Mojolicious#build_tx>.
420  
421 =head1 Extended MARKDOWN & POD
422  
423 You can place attributes like:
424  
425 =head2 id (# as prefix)
426  
427 =head2 classnames (dot as prefix and separator)
428  
429 =head2 css-style rules (key:value; colon separator and semicolon terminator)
430  
431 to markup elements as below.
432  
433 In MARKDOWN:
434  
435 # {#foo123 .class1 .class2 padding: 0 0.5rem;} Header 1
436 {.brown-text} brown paragraph text ...
437  
438 In POD:
439  
440 =head2 {.class1.blue-text border-bottom: 1px dotted;} Header 2
441
442 {.red-text} red color text...
443  
444 =head1 METHODS
445  
446 L<Mojolicious::Plugin::StaticShare> inherits all methods from
447 parent L<Mojolicious::Plugin> and implements the following new ones.
448  
449 =head2 register
450  
451 $plugin->register(Mojolicious->new);
452  
453 Register plugin in L<Mojolicious> application.
454  
455 =head1 MULTI PLUGIN
456  
457 Yep, possible:
458  
459 # Mojolicious
460 $app->config(...)
461 ->plugin('StaticShare', ...)
462 ->plugin('StaticShare', ...); # and so on ...
463
464 # Mojolicious::Lite
465 app->config(...)
466 ->plugin('StaticShare', ...)
467 ->plugin('StaticShare', ...) # and so on ...
468  
469  
470 =head1 UTF-8
471  
472 Everywhere and everything: module, files, content.
473  
474 =head1 WINDOWS OS
475  
476 It was not tested but I hope you dont worry and have happy.
477  
478 =head1 SEE ALSO
479  
480 L<Mojolicious::Plugin::Directory>
481  
482 L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>.
483  
484 =head1 AUTHOR
485  
486 Михаил Че (Mikhail Che), C<< <mche[-at-]cpan.org> >>
487  
488 =head1 BUGS / CONTRIBUTING
489  
490 Please report any bugs or feature requests at L<https://github.com/mche/Mojolicious-Plugin-StaticShare/issues>. Pull requests also welcome.
491  
492 =head1 COPYRIGHT
493  
494 Copyright 2017+ Mikhail Che.
495  
496 This library is free software; you can redistribute it and/or modify
497 it under the same terms as Perl itself.
498  
499 =cut
« StaticShare/Controller.pm ↑ Summary PODRenderer.pm »