Skip to content

Commit

Permalink
preparation for CPAN release
Browse files Browse the repository at this point in the history
  • Loading branch information
ksurent committed May 26, 2011
1 parent 74abcce commit 5fdef70
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 55 deletions.
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0.01_1 - Thu May 26 2011
- first CPAN release
10 changes: 10 additions & 0 deletions Makefile.PL
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;
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ HTTP client.
thinpack-ed scripts are easy to distribute.

BUGS:
No Windows support. Rudimentary parsing. Default --sudo for cpanm. Patches are welcome.
No Windows support. Rudimentary parsing. Default --sudo for cpanm. Donwloading cpanminus from third-party source. Patches are welcome.
121 changes: 121 additions & 0 deletions lib/App/ThinPacker.pm
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);
}
5 changes: 5 additions & 0 deletions script/thinpack
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);
54 changes: 0 additions & 54 deletions thinpack.pl

This file was deleted.

0 comments on commit 5fdef70

Please sign in to comment.