| 1 | package App::DAVThis; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | our $DATE = '2017-11-10'; # DATE | |||||||||||||
| 4 | 1 | our $VERSION = '0.001'; # VERSION | |||||||||||||
| 5 | |||||||||||||||
| 6 | 1 | ▶ | use 5.010001; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | ▶ | use Cwd; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use Getopt::Long; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use Pod::Usage; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||
| 15 | 0 | my $class = shift; | |||||||||||||
| 16 | 0 | my $self = bless {port => 4242, root => '.'}, $class; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 0 | ▶ | GetOptions($self, "help", "man", "port=i", | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | ) || pod2usage(2); | ||||||||||||||
| 20 | 0 | ▶ | pod2usage(1) if $self->{help}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | 0 | ▶ | pod2usage(-verbose => 2) if $self->{man}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | |||||||||||||||
| 23 | 0 | ▶ | if (@ARGV > 1) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 24 | 0 | pod2usage("$0: Too many roots, only single root supported"); | |||||||||||||
| 25 | } elsif (@ARGV) { | ||||||||||||||
| 26 | 0 | $self->{root} = shift @ARGV; | |||||||||||||
| 27 | } else { | ||||||||||||||
| 28 | 0 | $self->{root} = getcwd(); | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 0 | return $self; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | ▶ | sub run { | ||||||||||||
|
Subroutine
run: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 35 | 0 | require Filesys::Virtual::Plain; | |||||||||||||
| 36 | 0 | require HTTP::Daemon; | |||||||||||||
| 37 | 0 | require Net::DAV::Server; | |||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | my ($self) = @_; | |||||||||||||
| 40 | |||||||||||||||
| 41 | 0 | my $filesys = Filesys::Virtual::Plain->new({root_path => $self->{root}}); | |||||||||||||
| 42 | 0 | my $webdav = Net::DAV::Server->new(); | |||||||||||||
| 43 | 0 | $webdav->filesys($filesys); | |||||||||||||
| 44 | |||||||||||||||
| 45 | my $d = HTTP::Daemon->new( | ||||||||||||||
| 46 | LocalAddr => 'localhost', | ||||||||||||||
| 47 | LocalPort => $self->{port}, | ||||||||||||||
| 48 | 0 | ▶ | ReuseAddr => 1) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | or die "Can't start HTTP::Daemon on port $self->{port}: $!"; | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 0 | print "Please contact me at: ", $d->url, "\n"; | |||||||||||||
| 52 | 0 | ▶ | while (my $c = $d->accept) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 0 | ▶ | while (my $request = $c->get_request) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 0 | my $response = $webdav->run($request); | |||||||||||||
| 55 | 0 | $c->send_response ($response); | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | 0 | $c->close; | |||||||||||||
| 58 | 0 | undef($c); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 1 | 1; | |||||||||||||
| 63 | # ABSTRACT: Export the current directory over WebDAV | ||||||||||||||
| 64 | |||||||||||||||
| 65 | __END__ | ||||||||||||||