line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::revealup::cli::serve; |
2
|
1
|
|
|
1
|
|
839
|
use App::revealup::base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
3
|
1
|
|
|
1
|
|
1162
|
use Getopt::Long qw/GetOptionsFromArray/; |
|
1
|
|
|
|
|
10633
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
902
|
use File::ShareDir qw/dist_dir/; |
|
1
|
|
|
|
|
7047
|
|
|
1
|
|
|
|
|
65
|
|
5
|
1
|
|
|
1
|
|
1115
|
use Path::Tiny qw/path/; |
|
1
|
|
|
|
|
9432
|
|
|
1
|
|
|
|
|
53
|
|
6
|
1
|
|
|
1
|
|
768
|
use Plack::Runner; |
|
1
|
|
|
|
|
16177
|
|
|
1
|
|
|
|
|
29
|
|
7
|
1
|
|
|
1
|
|
820
|
use Pod::Usage; |
|
1
|
|
|
|
|
74967
|
|
|
1
|
|
|
|
|
163
|
|
8
|
1
|
|
|
1
|
|
624
|
use App::revealup::util; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
80
|
|
9
|
1
|
|
|
1
|
|
560
|
use App::revealup::builder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
509
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'plack_port' => 5000; |
12
|
|
|
|
|
|
|
has 'dry_run' => 0; |
13
|
|
|
|
|
|
|
has 'theme'; |
14
|
|
|
|
|
|
|
has 'transition'; |
15
|
|
|
|
|
|
|
has 'width'; |
16
|
|
|
|
|
|
|
has 'height'; |
17
|
|
|
|
|
|
|
has 'theme_path'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub run { |
20
|
0
|
|
|
0
|
0
|
|
my ($self, @args) = @_; |
21
|
0
|
|
|
|
|
|
my $opt; |
22
|
|
|
|
|
|
|
parse_options( |
23
|
|
|
|
|
|
|
\@args, |
24
|
|
|
|
|
|
|
'p|port=s' => \$opt->{plack_port}, |
25
|
|
|
|
|
|
|
'theme=s' => \$opt->{theme}, |
26
|
|
|
|
|
|
|
'transition=s' => \$opt->{transition}, |
27
|
|
|
|
|
|
|
'width=i' => \$opt->{width}, |
28
|
|
|
|
|
|
|
'height=i' => \$opt->{height}, |
29
|
|
|
|
|
|
|
'_dry-run' => \$opt->{dry_run}, |
30
|
0
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
for my $key (keys %$opt) { |
33
|
0
|
|
|
|
|
|
$self->$key( $opt->{$key} ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $filename = shift @args; |
37
|
0
|
|
0
|
|
|
|
my $builder = App::revealup::builder->new( |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
38
|
|
|
|
|
|
|
filename => $filename || '', |
39
|
|
|
|
|
|
|
theme => $self->theme || '', |
40
|
|
|
|
|
|
|
transition => $self->transition || '', |
41
|
|
|
|
|
|
|
width => $self->width || 0, |
42
|
|
|
|
|
|
|
height => $self->height || 0, |
43
|
|
|
|
|
|
|
); |
44
|
0
|
|
|
|
|
|
my $html = $builder->build_html(); |
45
|
0
|
0
|
|
|
|
|
if( !$html ) { |
46
|
0
|
|
|
|
|
|
system "perldoc App::revealup::cli::serve"; |
47
|
0
|
|
|
|
|
|
exit; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $app = $self->app($html); |
51
|
0
|
|
|
|
|
|
my $runner = Plack::Runner->new(); |
52
|
0
|
|
|
|
|
|
$runner->parse_options("--no-default-middleware"); |
53
|
0
|
|
|
|
|
|
$runner->set_options(port => $self->plack_port); |
54
|
0
|
0
|
|
|
|
|
$runner->run($app) if !$self->dry_run |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub app { |
58
|
0
|
|
|
0
|
0
|
|
my ($self, $html) = @_; |
59
|
|
|
|
|
|
|
return sub { |
60
|
0
|
|
|
0
|
|
|
my $env = shift; |
61
|
0
|
0
|
|
|
|
|
if ($env->{PATH_INFO} eq '/') { |
62
|
|
|
|
|
|
|
return [ |
63
|
0
|
|
|
|
|
|
200, |
64
|
|
|
|
|
|
|
['Content-Type' => 'text/html', 'Content-Length' => length $html], |
65
|
|
|
|
|
|
|
[$html] |
66
|
|
|
|
|
|
|
]; |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $path; |
70
|
|
|
|
|
|
|
# theme |
71
|
0
|
0
|
0
|
|
|
|
if($self->theme_path && $env->{PATH_INFO} =~ m!${self->theme_path}$!){ |
|
0
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
if($self->theme_path->exists) { |
73
|
0
|
|
|
|
|
|
$path = path('.', $self->theme_path); |
74
|
|
|
|
|
|
|
}else{ |
75
|
0
|
|
|
|
|
|
my $reveal_theme_path = App::revealup::util::share_path([qw/share revealjs css theme/]); |
76
|
0
|
|
|
|
|
|
$path = $reveal_theme_path->child($self->theme_path->basename); |
77
|
|
|
|
|
|
|
} |
78
|
0
|
0
|
|
|
|
|
return App::revealup::util::path_to_res($path) if $path->exists; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$path = path('.', $env->{PATH_INFO}); |
82
|
0
|
0
|
|
|
|
|
return App::revealup::util::path_to_res($path) if $path->exists; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $reveal_dir = App::revealup::util::share_path([qw/share/]); |
85
|
0
|
|
|
|
|
|
$path = $reveal_dir->child($env->{PATH_INFO}); |
86
|
0
|
0
|
|
|
|
|
return App::revealup::util::path_to_res($path) if $path->exists; |
87
|
0
|
|
|
|
|
|
App::revealup::util::warn("$path does not exist"); |
88
|
|
|
|
|
|
|
return [ |
89
|
0
|
|
|
|
|
|
404, |
90
|
|
|
|
|
|
|
['Content-Type' => 'text/plain'], |
91
|
|
|
|
|
|
|
['Not Found'] |
92
|
|
|
|
|
|
|
]; |
93
|
0
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |