| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use 5.008005; |
|---|
| 4 | use strict; |
|---|
| 5 | use warnings; |
|---|
| 6 | use Carp (); |
|---|
| 7 | |
|---|
| 8 | our $VERSION = '0.95'; |
|---|
| 9 | |
|---|
| 10 | use constant WIN32 => !!( $^O eq 'MSWin32' and $^X =~ /wperl\.exe/ ); |
|---|
| 11 | |
|---|
| 12 | local $| = 1; |
|---|
| 13 | local $SIG{__DIE__} = |
|---|
| 14 | $ENV{PADRE_DIE} |
|---|
| 15 | ? sub { print STDERR Carp::longmess "\nDIE: @_\n" . ( "-" x 80 ) . "\n" } |
|---|
| 16 | : $SIG{__DIE__}; |
|---|
| 17 | |
|---|
| 18 | # Must run using wxPerl on OS X. |
|---|
| 19 | if ( $^O eq 'darwin' and $^X !~ m{/wxPerl} ) { |
|---|
| 20 | require File::Which; |
|---|
| 21 | require File::Basename; |
|---|
| 22 | require File::Spec; |
|---|
| 23 | |
|---|
| 24 | my $this_perl = File::Which::which($^X) || $^X; |
|---|
| 25 | if ( -l $this_perl ) { |
|---|
| 26 | my $link = readlink $this_perl; |
|---|
| 27 | $this_perl = $link if $link; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | my $dir = File::Basename::dirname($this_perl); |
|---|
| 31 | my $wx_perl = File::Spec->catfile( $dir, 'wxPerl' ); |
|---|
| 32 | my $perl = |
|---|
| 33 | $wx_perl && -e $wx_perl && -x _ |
|---|
| 34 | ? $wx_perl |
|---|
| 35 | : File::Which::which('wxPerl'); |
|---|
| 36 | chomp($perl); |
|---|
| 37 | if ( -e $perl ) { |
|---|
| 38 | warn "spawning 'wxPerl' interpreter for OS X\n"; |
|---|
| 39 | system( $perl, '-S', $0, @ARGV ); |
|---|
| 40 | } else { |
|---|
| 41 | warn "padre cannot find wxPerl executable (which it requires on OS X)\n"; |
|---|
| 42 | } |
|---|
| 43 | exit 0; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | # Disable overlay scrollbar on Linux. |
|---|
| 47 | # Done ugly this way to satisfy Perl::Critic (grrr) |
|---|
| 48 | local $ENV{LIBOVERLAY_SCROLLBAR} = ( $^O eq 'linux' ) ? 0 : $ENV{LIBOVERLAY_SCROLLBAR}; |
|---|
| 49 | |
|---|
| 50 | # Handle special command line cases early, because options like --home |
|---|
| 51 | # MUST be processed before the Padre.pm library is loaded. |
|---|
| 52 | my $USAGE = ''; |
|---|
| 53 | my $SHOWVERSION = ''; |
|---|
| 54 | my $HOME = undef; |
|---|
| 55 | my $RESET = undef; |
|---|
| 56 | my $SESSION = undef; |
|---|
| 57 | my $PRELOAD = undef; |
|---|
| 58 | my $DESKTOP = undef; |
|---|
| 59 | my $ACTIONS = undef; |
|---|
| 60 | my $LOCALE = undef; |
|---|
| 61 | if ( grep {/^-/} @ARGV ) { |
|---|
| 62 | |
|---|
| 63 | # Avoid loading Getopt::Long entirely if we can, |
|---|
| 64 | # sneakily saving a meg or so of RAM. |
|---|
| 65 | require Getopt::Long; |
|---|
| 66 | Getopt::Long::GetOptions( |
|---|
| 67 | 'help|usage' => \$USAGE, |
|---|
| 68 | 'version' => \$SHOWVERSION, |
|---|
| 69 | 'home=s' => \$HOME, |
|---|
| 70 | 'reset' => \$RESET, |
|---|
| 71 | 'session=s' => \$SESSION, |
|---|
| 72 | 'desktop' => \$DESKTOP, |
|---|
| 73 | 'actionqueue=s' => \$ACTIONS, |
|---|
| 74 | 'locale=s' => \$LOCALE, |
|---|
| 75 | |
|---|
| 76 | # Keep this sekrit for now --ADAMK |
|---|
| 77 | 'preload' => \$PRELOAD, |
|---|
| 78 | ) or $USAGE = 1; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | ##################################################################### |
|---|
| 86 | # Special Execution Modules |
|---|
| 87 | |
|---|
| 88 | # Padre command line usage |
|---|
| 89 | if ($USAGE) { |
|---|
| 90 | print <<"END_USAGE"; |
|---|
| 91 | Usage: $0 [FILENAMES] |
|---|
| 92 | |
|---|
| 93 | --help Shows this help message |
|---|
| 94 | --home=dir Forces Padre "home" directory to a specific location |
|---|
| 95 | --reset Flush entire local config directory and reset to defaults |
|---|
| 96 | --session=name Open given session during Padre startup |
|---|
| 97 | --version Prints Padre version and quits |
|---|
| 98 | --desktop Integrate Padre with your desktop |
|---|
| 99 | --actionqueue=list Run a list of comma-separated actions after Padre startup |
|---|
| 100 | --locale=name Locale name to use |
|---|
| 101 | |
|---|
| 102 | END_USAGE |
|---|
| 103 | exit(1); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | # Lock in the home and constants, which are needed for everything else |
|---|
| 107 | local $ENV{PADRE_HOME} = defined($HOME) ? $HOME : $ENV{PADRE_HOME}; |
|---|
| 108 | require Padre::Constant; |
|---|
| 109 | |
|---|
| 110 | # Padre version |
|---|
| 111 | if ($SHOWVERSION) { |
|---|
| 112 | require Padre; |
|---|
| 113 | message("Perl Application Development and Refactoring Environment $Padre::VERSION"); |
|---|
| 114 | exit(0); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | # Destroy and reinitialise our config directory |
|---|
| 118 | if ($RESET) { |
|---|
| 119 | require File::Remove; |
|---|
| 120 | File::Remove::remove( \1, Padre::Constant::CONFIG_DIR() ); |
|---|
| 121 | Padre::Constant::init(); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | if ($DESKTOP) { |
|---|
| 125 | require Padre::Desktop; |
|---|
| 126 | unless ( Padre::Desktop::desktop() ) { |
|---|
| 127 | error("--desktop not implemented for $^O"); |
|---|
| 128 | } |
|---|
| 129 | exit(1); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | # local $ENV{PADRE_PAR_PATH} = $ENV{PAR_TEMP} || ''; |
|---|
| 133 | |
|---|
| 134 | # If we have an action queue then we are running for automation reasons. |
|---|
| 135 | # Avoid the startup logic and continue to the main startup. |
|---|
| 136 | unless ( defined $ACTIONS ) { |
|---|
| 137 | |
|---|
| 138 | # Run the Padre startup sequence before we load the main application |
|---|
| 139 | require Padre::Startup; |
|---|
| 140 | unless ( Padre::Startup::startup() ) { |
|---|
| 141 | |
|---|
| 142 | # Startup process says to abort the main load and exit now |
|---|
| 143 | exit(0); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | SCOPE: { |
|---|
| 148 | local $@; |
|---|
| 149 | eval { |
|---|
| 150 | require Padre; |
|---|
| 151 | |
|---|
| 152 | # Load the entire application into memory immediately |
|---|
| 153 | Padre->import(':everything') if $PRELOAD; |
|---|
| 154 | |
|---|
| 155 | # use Aspect; |
|---|
| 156 | # aspect( 'NYTProf', |
|---|
| 157 | # call qr/^Padre::/ & |
|---|
| 158 | # call qr/\b(?:refresh|update)\w*\z/ & ! |
|---|
| 159 | # call qr/^Padre::(?:Locker|Wx::Progress)::/ |
|---|
| 160 | # ); |
|---|
| 161 | }; |
|---|
| 162 | if ( $@ ) { |
|---|
| 163 | # Major startup failure! |
|---|
| 164 | # Handle a few specialised cases we understand |
|---|
| 165 | if ( $@ =~ /Schema user_version mismatch/ ) { |
|---|
| 166 | error("Padre configuration database schema invalid"); |
|---|
| 167 | if ( WIN32 ) { |
|---|
| 168 | require Win32; |
|---|
| 169 | my $rv = Win32::MsgBox( |
|---|
| 170 | "Reset your configuration to try and fix it?", |
|---|
| 171 | 4, "Padre", |
|---|
| 172 | ); |
|---|
| 173 | if ( $rv == 6 ) { |
|---|
| 174 | require File::Remove; |
|---|
| 175 | File::Remove::remove( \1, Padre::Constant::CONFIG_DIR() ); |
|---|
| 176 | error("Configuration directory reset"); |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | exit(1); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | # Handle other generic errors |
|---|
| 183 | my $message = $@; |
|---|
| 184 | $message =~ s/ at .*?line.*$//; |
|---|
| 185 | error("Major Startup Error: '$message'"); |
|---|
| 186 | exit(1); |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | # Build the application |
|---|
| 191 | my $ide = Padre->new( |
|---|
| 192 | files => \@ARGV, |
|---|
| 193 | session => $SESSION, |
|---|
| 194 | actionqueue => $ACTIONS, |
|---|
| 195 | startup_locale => $LOCALE, |
|---|
| 196 | ) or die 'Failed to create Padre instance'; |
|---|
| 197 | |
|---|
| 198 | # Start the application |
|---|
| 199 | $ide->run; |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | ###################################################################### |
|---|
| 206 | # Support Functions |
|---|
| 207 | |
|---|
| 208 | sub message { |
|---|
| 209 | my $message = shift; |
|---|
| 210 | if ( WIN32 ) { |
|---|
| 211 | # No console under wperl, so use native Win32 messaging |
|---|
| 212 | require Win32; |
|---|
| 213 | Win32::MsgBox($message, 0, "Padre"); |
|---|
| 214 | } else { |
|---|
| 215 | print $message . "\n"; |
|---|
| 216 | } |
|---|
| 217 | return 1; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | sub error { |
|---|
| 221 | my $message = shift; |
|---|
| 222 | if ( WIN32 ) { |
|---|
| 223 | # No console under wperl, so use native Win32 messaging |
|---|
| 224 | require Win32; |
|---|
| 225 | Win32::MsgBox($message, 0, "Padre"); |
|---|
| 226 | } else { |
|---|
| 227 | print STDERR $message . "\n"; |
|---|
| 228 | } |
|---|
| 229 | return 1; |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | # Copyright 2008-2012 The Padre development team as listed in Padre.pm. |
|---|
| 233 | # LICENSE |
|---|
| 234 | # This program is free software; you can redistribute it and/or |
|---|
| 235 | # modify it under the same terms as Perl 5 itself. |
|---|