#!/usr/bin/env perl
use 5.008003;
use strict;
our $VERSION = '0.20';
use Cwd 'cwd', 'abs_path';
use FindBin;
use Config;

sub find_base {
    return $ENV{SPORK_BASE} if defined $ENV{SPORK_BASE};

    my $base = $FindBin::Bin;
    my $bin = $0;
    $bin =~ s/.*\///;
    $bin = "$base/$bin";
    my $home = cwd();
    while (-l $bin) {
        chdir $base;
        $bin = abs_path(readlink $bin);
        $base = $bin;
        $base =~ s/(.*)\/.*/$1/;
    }
    chdir $home;
    $base = abs_path("$base/../../..");

    die "*ERROR*: Can't locate Spork base repository."
        unless -d "$base/lib/Spork" and -d "$base/src/core/Spork";
    $ENV{SPORK_BASE} = $base;
    return $base;
} 

BEGIN {
    my @env_files = qw(spork.env);
    push @env_files, "$ENV{HOME}/.sporkrc/spork.env" if defined $ENV{HOME};
    my $fh;
    for (@env_files) {
        if (open $fh, $_) {
            do {
                $ENV{$1} ||= $2 if /^(\w+)\s*=\s*['"]?(.*?)['"]?\s*$/;
            } for <$fh>;
            last;
        }
    }

    if ($ENV{SPORK_TEST_CLEAN}) {
        @INC = (
            $Config::Config{archlib},
            $Config::Config{privlib},
        ); 
    }

    $ENV{SPORK_LIB_PATH} ||= find_base() . "/lib";
}

use lib grep { -e } split /:/, $ENV{SPORK_LIB_PATH} || 'lib';
use Spork::Boot;
Spork::Boot->boot->main->hub->command->process(@ARGV);

=comment
Lastlog:
12:52 < lamech> no. Spork. not Spoon. sorry.
12:53 < lamech> point being Spork's makefile doesn't specify Kwiki::Cache, it 
          specifies Kwiki, so you have to install Kwiki::Cache separately after 
          guessing.
13:04 < ingy> lamech: do you have spork working?
13:05 < ingy> I have pulled the spork code into 
          http://svn.kwiki.org/kwiki/trunk/
13:06 < ingy> need to get Spork working in there
13:06 < diotalevi> Oh btw, I just consulted my notes from the last time I tried 
          using Spork. plugin_classes can't be set in 
          my-presentation/config.yaml just throws errors so it has to be set at 
          ~/.sporkrc/config.yaml.
13:07 < ingy> yeah, I need to decide whether or not I will use spork next week 
          in YAPC::Tokyo
13:40 < diotalevi> Hey lamech, maybe you also want to see 
          http://perlmonks.org/?node_id=516229 about Spork.
=cut

__END__

=head1 NAME

spork - The Spork Command Line Utility

=head1 USAGE

    > mkdir my-slideshow
    > cd my-slideshow
    > spork -new
    > spork -showconf
    > spork -make
    > spork -start

=head1 DESCRIPTION

Spork is a Perl module for creating standalone HTML slideshows from Kwiki
markup.

=head1 AUTHOR

Brian Ingerson <INGY@cpan.org>

=head1 COPYRIGHT

Copyright (c) 2004. Brian Ingerson. All rights reserved.

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

See http://www.perl.com/perl/misc/Artistic.html

=cut

# vim: set ft=perl:
