#!/usr/bin/perl

use warnings;
use strict;
use Plack::Runner;

our $VERSION = '0.00100';

sub version {
    print "$VERSION\n";
}

my $preload_app;
my $dezi_config_file;
my $server_class = 'Dezi::Server';

require Getopt::Long;
Getopt::Long::Configure( "no_ignore_case", "no_auto_abbrev", "pass_through" );
Getopt::Long::GetOptions(
    "preload-app"  => \$preload_app,
    "dezi-config"  => \$dezi_config_file,
    "server-class" => \$server_class,
);

my @args = (

    #env        => 'deployment',
    version_cb => \&version
);
if ( !$preload_app ) {
    push @args, 'loader' => 'Delayed';
}
my $config = {};
if ($dezi_config_file) {
    require Config::Any;
    $config = Config::Any->load_files( { files => [$dezi_config_file] } );
}

eval "use $server_class";
my $app = $server_class->app( engine_config => $config );

my @argv = @ARGV;

my $runner = Plack::Runner->new(@args);
$runner->parse_options(@argv);
$runner->set_options( argv => \@argv );
$runner->run($app);

__END__

=head1 NAME

Dezi - search platform based on Apache Lucy, Swish3 and Plack

=head1 SYNOPSIS

Start the Dezi server, listening on port 5000:

 % dezi -p 5000

Add a document B<foo> to the index:

 % curl -XPOST http://localhost:5000/foo \
   -d '<doc><title>bar</title>hello world</doc>' \
   -H 'Content-Type: application/xml'
   
Search the index:

 % curl 'http://localhost:5000/?q=bar'

=head1 DESCRIPTION

Dezi is a search platform based on Apache Lucy, Swish3, Plack,
Search::OpenSearch and Search::Query. 

Dezi integrates several CPAN search libraries into one
easy-to-use interface.

=head1 AUTHOR

Peter Karman, C<< <karman at cpan.org> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-dezi at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dezi>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.


=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Dezi


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dezi>

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/Dezi>

=item * CPAN Ratings

L<http://cpanratings.perl.org/d/Dezi>

=item * Search CPAN

L<http://search.cpan.org/dist/Dezi/>

=back


=head1 ACKNOWLEDGEMENTS

Marvin Humphrey for a great library in Apache Lucy.

The Plack community.

=head1 COPYRIGHT & LICENSE

Copyright 2011 Peter Karman.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.


=cut

