package App::DAVThis;

our $DATE = '2017-11-10'; # DATE
our $VERSION = '0.001'; # VERSION

use 5.010001;
use strict;
use warnings;

use Cwd;
use Getopt::Long;
use Pod::Usage;

sub new {
    my $class = shift;
    my $self = bless {port => 4242, root => '.'}, $class;

    GetOptions($self, "help", "man", "port=i",
           ) || pod2usage(2);
    pod2usage(1) if $self->{help};
    pod2usage(-verbose => 2) if $self->{man};

    if (@ARGV > 1) {
        pod2usage("$0: Too many roots, only single root supported");
    } elsif (@ARGV) {
        $self->{root} = shift @ARGV;
    } else {
        $self->{root} = getcwd();

    return $self;

sub run {
    require Filesys::Virtual::Plain;
    require HTTP::Daemon;
    require Net::DAV::Server;

    my ($self) = @_;

    my $filesys = Filesys::Virtual::Plain->new({root_path => $self->{root}});
    my $webdav = Net::DAV::Server->new();

    my $d = HTTP::Daemon->new(
        LocalAddr => 'localhost',
        LocalPort => $self->{port},
        ReuseAddr => 1)
        or die "Can't start HTTP::Daemon on port $self->{port}: $!";

    print "Please contact me at: ", $d->url, "\n";
    while (my $c = $d->accept) {
        while (my $request = $c->get_request) {
            my $response = $webdav->run($request);
            $c->send_response ($response);

# ABSTRACT: Export the current directory over WebDAV



=encoding UTF-8

=head1 NAME

App::DAVThis - Export the current directory over WebDAV

=head1 VERSION

This document describes version 0.001 of App::DAVThis (from Perl distribution App-DAVThis), released on 2017-11-10.


 # Not to be used directly, see dav_this command


=head1 METHODS

=head2 new

=head2 run



Please visit the project's homepage at L<>.

=head1 SOURCE

Source repository is at L<>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired

=head1 SEE ALSO

=head1 AUTHOR

perlancar <>


This software is copyright (c) 2017 by

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.