#!/usr/bin/perl 

use strict;
use warnings;
use Getopt::Long ();

$| = 1;

#must run using wxPerl on OSX.
if (($^O eq 'darwin') and ($^X !~ m{/wxPerl\.app/})) {
    my $perl_path = `which wxPerl`;
    chomp($perl_path);
    if (-e $perl_path) {
        warn "spawning 'wxPerl' interpreter for OSX\n";
        system($perl_path, '-S', $0, @ARGV);
    } else {
        warn "padre cannot find wxPerl executable (which it requires on OSX)\n" ;
    }
    exit 0;
}

# Handle special command line cases early, because options like --home
# MUST be processed before the Padre.pm library is loaded.
my $USAGE   = '';
my $HOME    = undef;
my $session = undef;
my $getopt = Getopt::Long::GetOptions(
	'help'      => \$USAGE,
	'home=s'    => \$HOME,
	'session=s' => \$session,
);
if ( $USAGE or ! $getopt ) {
	print <<"END_USAGE";
Usage: $0 [FILENAMES]

--home=dir        Forces Padre's "home" directory to a specific location
--help            Shows this help message
--session=name    Open given session during Padre startup

END_USAGE
	exit(1);
}
if ( defined $HOME ) {
	$ENV{PADRE_HOME} = $HOME;
}

require threads;
require threads::shared;

$ENV{PADRE_PAR_PATH} = $ENV{PAR_TEMP}||'';

my %opts = (
    files   => \@ARGV,
    session => $session,
);
    
require Padre;
my $app = Padre->new(%opts);
$app->run;

# Copyright 2008-2009 The Padre development team as listed in Padre.pm.
# LICENSE
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl 5 itself.
