forked from kappa/App-ThinPacker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
139 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
0.01_1 - Thu May 26 2011 | ||
- first CPAN release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use inc::Module::Install; | ||
|
||
all_from 'lib/App/ThinPacker.pm'; | ||
|
||
requires 'PPI'; | ||
requires 'Pod::Usage'; | ||
|
||
install_script 'script/thinpack'; | ||
|
||
WriteAll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package App::ThinPacker; | ||
|
||
=pod | ||
=head1 NAME | ||
App::ThinPacker - enable your scripts to autoinstall their dependicies | ||
=head1 DESCRIPTION | ||
Enables your scripts to autoinstall their dependecies by injecting a small piece of code which downloads cpanminus and uses it to install all the depenencies. | ||
=head1 SYNOPSIS | ||
thinpack your-script.pl > your-script-dist.pl | ||
=head1 SEE ALSO | ||
L<App::FatPacker> | ||
L<App::cpanmminus> | ||
=head1 BUGS AND TODO | ||
=over 4 | ||
=item No Windows support | ||
=item Rudimentary parsing | ||
=item Default --sudo for cpanm | ||
=item Downloading cpanm from third-party source | ||
=back | ||
=head1 AUTHOR | ||
Alex Kapranoff | ||
=head1 CONTRIBUTORS | ||
Alexey Surikov E<lt>ksuri@cpan.orgE<gt> | ||
=head1 LICENSE | ||
This program is free software, you can redistribute it under the same terms as Perl itself. | ||
=cut | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use PPI; | ||
use Pod::Find; | ||
use Pod::Usage; | ||
|
||
our $VERSION = '0.01_1'; | ||
|
||
sub run { | ||
my $arg = shift or usage(); | ||
usage(2) if $arg eq '-h' or $arg eq '--help'; | ||
|
||
my $ppi = PPI::Document->new($arg) or usage(); | ||
my $includes = $ppi->find('Statement::Include'); | ||
|
||
my $deps = join ' ', | ||
grep { $_ ne 'strict' && $_ ne 'warnings' } | ||
map { $_->module } | ||
@$includes; | ||
|
||
my $inject = join '', map { s/%%DEPS%%/$deps/; $_ } <DATA>; | ||
|
||
open my $script, '<', $arg or exit print "Cannot open $arg: $!\n"; | ||
my $not_injected = 1; | ||
while (my $line = <$script>) { | ||
if ($line =~ /^use / && $not_injected) { | ||
print "BEGIN {\n$inject\n}\n"; | ||
$not_injected = 0; | ||
} | ||
|
||
print $line; | ||
} | ||
} | ||
|
||
sub usage { | ||
pod2usage( | ||
-verbose => $_[0] || 0, | ||
-output => \*STDERR, | ||
-input => Pod::Find::pod_where( | ||
{ -inc => 1 }, | ||
__PACKAGE__, | ||
), | ||
); | ||
} | ||
|
||
__DATA__ | ||
package main; | ||
use IO::Socket::INET; | ||
my @deps = qw(%%DEPS%%); | ||
my @inst; | ||
for my $dep (@deps) { | ||
eval "require $dep"; | ||
push @inst, $dep if $@; | ||
} | ||
if (@inst) { | ||
local $@; | ||
eval "require App::cpanminus"; | ||
if ($@) { | ||
my $sock = IO::Socket::INET->new('kapranoff.ru:80'); | ||
print $sock join "\r\n", "GET /cpanm HTTP/1.0", | ||
"Connection: close", | ||
"\r\n"; | ||
my $cpanm = do { local $/; <$sock> }; | ||
close $sock; | ||
open my $sudoperl, '|perl - --self-upgrade --sudo'; | ||
print $sudoperl $cpanm; | ||
close $sudoperl; | ||
} | ||
system(qw/cpanm --sudo/, @inst); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env perl | ||
|
||
use App::ThinPacker; | ||
|
||
App::ThinPacker::run(@ARGV); |
This file was deleted.
Oops, something went wrong.