#!/usr/bin/env perl

use v5.36;

use Getopt::Long;
use Plack::App::MCCS;
use Plack::Runner;

my $defaults = {};

# first, parse our own options
Getopt::Long::Configure qw/no_ignore_case no_auto_abbrev pass_through/;
Getopt::Long::GetOptions(
    'no-minify'   => \$defaults->{no_minify},
    'no-compress' => \$defaults->{no_compress},
    'no-etag'     => \$defaults->{no_etag}
);

# now let Plack::Runner parse plackup options
my $runner = Plack::Runner->new();
$runner->parse_options(@ARGV);

# after this, the root directory should be in $runner->{argv}
my $root = $runner->{argv}->[0] || './';
print "Serving files from $root\n";

# create the Plack::App::MCCS app and start running it
my %options = ( root => $root );
foreach (qw/minify compress etag/) {
    $options{defaults}->{$_} = 0
      if $defaults->{"no_$_"};
}
$runner->run( Plack::App::MCCS->new(%options)->to_app );

__END__
=head1 NAME

mccs - start a static file server using Plack::App::MCCS

=head1 SYNOPSIS

	# on the command line

	# start serving current directory on port 5000
	mccs

	# start serving a directory on port 80 using Starman
	mccs -s Starman --listen :80 /some/directory

	# serve without minification, compression and etag creation
	mccs --no-minify --no-compress --no-etag

=head1 DESCRIPTION

C<mccs> provides a quick and easy way to start serving files from a directory
using L<Plack::App::MCCS>. It loads C<MCCS> with L<Plack::Runner>, so it works
just like L<plackup> and accepts all options C<plackup> accepts. Use whatever
Plack handler you like.

Just like C<MCCS>, all options are turned on by default, so C<mccs> will attempt
to minify and compress appropriate files, and create ETags. You can disable this
with C<--no-minify>, C<--no-compress> and C<--no-etag>, respectively.

=head1 BUGS AND LIMITATIONS

Please report any bugs or feature requests to
C<bug-Plack-App-MCCS@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Plack-App-MCCS>.

=head1 SEE ALSO

L<Plack::App::MCCS>, L<Plack::Middleware::MCCS>, L<Plack::Runner>, L<plackup>.

=head1 AUTHOR

Ido Perlmuter <ido@ido50.net>

=head1 LICENSE AND COPYRIGHT

Copyright (c) 2011-2023, Ido Perlmuter C<< ido@ido50.net >>.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
