| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' |
|---|
| 4 | if 0; # not running under some shell |
|---|
| 5 | |
|---|
| 6 | use 5.008005; |
|---|
| 7 | use strict; |
|---|
| 8 | use warnings; |
|---|
| 9 | |
|---|
| 10 | BEGIN { |
|---|
| 11 | # use local::lib if available |
|---|
| 12 | my ($HOME) = $ENV{HOME} =~ /^([\w\/]+)$/; |
|---|
| 13 | if ( $HOME and -d "$HOME/perl5/lib/perl5" ) { |
|---|
| 14 | eval("use lib '$HOME/perl5/lib/perl5'"); |
|---|
| 15 | } |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | use File::Which (); |
|---|
| 19 | use Getopt::Long (); |
|---|
| 20 | use Carp (); |
|---|
| 21 | use Pod::Usage (); |
|---|
| 22 | |
|---|
| 23 | $| = 1; |
|---|
| 24 | |
|---|
| 25 | if ( $ENV{PADRE_DIE} ) { |
|---|
| 26 | $SIG{__DIE__} = sub { print STDERR Carp::longmess "\nDIE: @_\n" . ( "-" x 80 ) . "\n" }; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | # Must run using wxPerl on OS X. |
|---|
| 30 | if ( $^O eq 'darwin' and $^X !~ m{/wxPerl\.app/} ) { |
|---|
| 31 | _spawn_wx_perl(); |
|---|
| 32 | exit(0); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | # Handle special command line cases early, because options like --home |
|---|
| 36 | # MUST be processed before the Padre.pm library is loaded. |
|---|
| 37 | |
|---|
| 38 | my $USAGE = ''; |
|---|
| 39 | my $VERSION = ''; |
|---|
| 40 | my $HOME = undef; |
|---|
| 41 | my $SESSION = undef; |
|---|
| 42 | my $DESKTOP = undef; |
|---|
| 43 | |
|---|
| 44 | my $getopt = Getopt::Long::GetOptions( |
|---|
| 45 | 'help' => \$USAGE, |
|---|
| 46 | 'home=s' => \$HOME, |
|---|
| 47 | 'session=s' => \$SESSION, |
|---|
| 48 | 'desktop' => \$DESKTOP, |
|---|
| 49 | 'version' => \$VERSION, |
|---|
| 50 | ); |
|---|
| 51 | |
|---|
| 52 | if ( $USAGE or !$getopt ) { |
|---|
| 53 | Pod::Usage::pod2usage(1); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if ( defined $HOME ) { |
|---|
| 57 | $ENV{PADRE_HOME} = $HOME; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | require threads; |
|---|
| 61 | require threads::shared; |
|---|
| 62 | |
|---|
| 63 | $ENV{PADRE_PAR_PATH} = $ENV{PAR_TEMP} || ''; |
|---|
| 64 | |
|---|
| 65 | my %opts = ( |
|---|
| 66 | files => \@ARGV, |
|---|
| 67 | session => $SESSION, |
|---|
| 68 | ); |
|---|
| 69 | |
|---|
| 70 | require Padre; |
|---|
| 71 | |
|---|
| 72 | if ($VERSION) { |
|---|
| 73 | _print_version(); |
|---|
| 74 | exit(0); |
|---|
| 75 | } |
|---|
| 76 | elsif ($DESKTOP) { |
|---|
| 77 | _desktop_integration(); |
|---|
| 78 | exit(1); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | my $app = Padre->new(%opts); |
|---|
| 82 | |
|---|
| 83 | if ( !$app ) { |
|---|
| 84 | |
|---|
| 85 | # Single instance worked correctly |
|---|
| 86 | exit(0); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | # Start the application |
|---|
| 90 | $app->run; |
|---|
| 91 | |
|---|
| 92 | sub _print_version { |
|---|
| 93 | my $msg = "Perl Application Development and Refactoring Environment $Padre::VERSION\n"; |
|---|
| 94 | if ( $^O eq 'MSWin32' and $^X =~ /wperl\.exe/ ) { |
|---|
| 95 | |
|---|
| 96 | # Under wperl, there is no console so we will use |
|---|
| 97 | # a message box |
|---|
| 98 | require Padre::Wx; |
|---|
| 99 | Wx::MessageBox( $msg, Wx::gettext("Version"), Wx::wxOK(), ); |
|---|
| 100 | } |
|---|
| 101 | else { |
|---|
| 102 | print $msg; |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | sub _desktop_integration { |
|---|
| 107 | if ( $^O eq 'MSWin32' ) { |
|---|
| 108 | |
|---|
| 109 | # Integrate with registry via regedit... |
|---|
| 110 | # VBScript and registry on vista = Does not work! |
|---|
| 111 | my ( $reg, $regfile ) = File::Temp::tempfile( SUFFIX => '.reg' ); |
|---|
| 112 | print $reg <<'REG'; |
|---|
| 113 | Windows Registry Editor Version 5.00 |
|---|
| 114 | |
|---|
| 115 | [HKEY_CLASSES_ROOT\*\shell\Edit with Padre] |
|---|
| 116 | |
|---|
| 117 | [HKEY_CLASSES_ROOT\*\shell\Edit with Padre\Command] |
|---|
| 118 | @="c:\\strawberry\\perl\\bin\\padre.exe \"%1\"" |
|---|
| 119 | REG |
|---|
| 120 | close $reg; |
|---|
| 121 | |
|---|
| 122 | # Create Padre's Desktop Shortcut |
|---|
| 123 | require File::Temp; |
|---|
| 124 | my ( $vbs, $vbsfile ) = File::Temp::tempfile( SUFFIX => '.vbs' ); |
|---|
| 125 | print $vbs <<'CODE'; |
|---|
| 126 | ' Create a Padre shortcut on the current user's desktop |
|---|
| 127 | Set shell = CreateObject("WScript.Shell") |
|---|
| 128 | desktop = shell.SpecialFolders("Desktop") |
|---|
| 129 | Set shortcut = shell.CreateShortcut(desktop & "\Padre.lnk") |
|---|
| 130 | shortcut.Description = "Padre - The Perl IDE" |
|---|
| 131 | shortcut.TargetPath = "C:\strawberry\perl\bin\padre.exe" |
|---|
| 132 | shortcut.WorkingDirectory = "c:\strawberry\perl\bin" |
|---|
| 133 | shortcut.Save |
|---|
| 134 | MsgBox "Padre has created a shortcut on your desktop", vbOKOnly Or vbInformation, "Information" |
|---|
| 135 | CODE |
|---|
| 136 | |
|---|
| 137 | print $vbs <<"CODE"; |
|---|
| 138 | ' Now adding "Edit with Padre" to shell context menu |
|---|
| 139 | shell.Run("regedit.exe /S ""$regfile"""), 1, true |
|---|
| 140 | MsgBox """Edit with Padre"" has been added to your right click menu", vbOKOnly Or vbInformation, "Confirmation" |
|---|
| 141 | CODE |
|---|
| 142 | close $vbs; |
|---|
| 143 | system(qq{wscript "$vbsfile"}); |
|---|
| 144 | |
|---|
| 145 | } |
|---|
| 146 | elsif ( ( $^O =~ /linux|bsd/i ) ) { |
|---|
| 147 | |
|---|
| 148 | # Create Padre.desktop launcher on KDE/gnome |
|---|
| 149 | my $filename = "$ENV{HOME}/Desktop/Padre.desktop"; |
|---|
| 150 | open my $fh, ">", $filename |
|---|
| 151 | or die "Cannot create $filename: $!\n"; |
|---|
| 152 | require Padre::Util; |
|---|
| 153 | my $logo = Padre::Util::sharedir('icons/padre/64x64/logo.png'); |
|---|
| 154 | print $fh <<"DESKTOP"; |
|---|
| 155 | [Desktop Entry] |
|---|
| 156 | Name=Padre |
|---|
| 157 | Comment=Padre - The Perl IDE |
|---|
| 158 | Exec=/usr/local/bin/padre |
|---|
| 159 | Icon=$logo |
|---|
| 160 | Terminal=false |
|---|
| 161 | Type=Application |
|---|
| 162 | Categories=Development;Utility; |
|---|
| 163 | MimeType=text/plain;application/x-perl;application/x-perl6; |
|---|
| 164 | DESKTOP |
|---|
| 165 | close $fh; |
|---|
| 166 | } |
|---|
| 167 | else { |
|---|
| 168 | warn "--desktop not implemented for " . $^O . "\n"; |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | sub _spawn_wx_perl { |
|---|
| 173 | my $perl = scalar File::Which::which('wxPerl'); |
|---|
| 174 | chomp($perl); |
|---|
| 175 | |
|---|
| 176 | if ( -e $perl ) { |
|---|
| 177 | warn "spawning 'wxPerl' interpreter for OS X\n"; |
|---|
| 178 | system( $perl, '-S', $0, @ARGV ); |
|---|
| 179 | } |
|---|
| 180 | else { |
|---|
| 181 | warn "padre cannot find wxPerl executable (which it requires on OS X)\n"; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | exit 0; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | __END__ |
|---|
| 188 | |
|---|
| 189 | =head1 NAME |
|---|
| 190 | |
|---|
| 191 | padre - the perl IDE |
|---|
| 192 | |
|---|
| 193 | =head1 SYNOPSIS |
|---|
| 194 | |
|---|
| 195 | padre [options] [filenames] |
|---|
| 196 | |
|---|
| 197 | =head2 OPTIONS |
|---|
| 198 | |
|---|
| 199 | =over |
|---|
| 200 | |
|---|
| 201 | =item --home=dir |
|---|
| 202 | |
|---|
| 203 | Forces Padre's "home" directory to a specific location |
|---|
| 204 | |
|---|
| 205 | =item --help |
|---|
| 206 | |
|---|
| 207 | Shows this help message |
|---|
| 208 | |
|---|
| 209 | =item --session=name |
|---|
| 210 | |
|---|
| 211 | Open given session during Padre startup |
|---|
| 212 | |
|---|
| 213 | =item --version |
|---|
| 214 | |
|---|
| 215 | Prints Padre version and quits |
|---|
| 216 | |
|---|
| 217 | =back |
|---|
| 218 | |
|---|
| 219 | =head1 COPYRIGHT |
|---|
| 220 | |
|---|
| 221 | Copyright 2008-2009 The Padre development team as listed in Padre.pm. |
|---|
| 222 | |
|---|
| 223 | =head1 LICENSE |
|---|
| 224 | |
|---|
| 225 | This program is free software; you can redistribute it and/or |
|---|
| 226 | modify it under the same terms as Perl 5 itself. |
|---|