summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl0/bin/cpaninject
blob: 12679fb1737a78d566050fdbc3650da3a04af014 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/perl

=pod

=head1 NAME

cpaninject - Inject a distribution for installation via the CPAN shell

=head1 SYNOPSIS

  # Add the distribution
  cpaninject myperlmodule.tar.gz
  
  # And then install it from the cpan shell
  cpan> install LOCAL/myperlmodule.tar.gz

=head1 DESCRIPTION

B<cpaninject> is a small front-end application for the L<CPAN::Inject>
module.

It takes any arbitrary Perl distribution tarball (open source or
otherwise) and injects it into the local CPAN file cache, smoothing
some metadata files to make it look as if it came from CPAN.

It makes use the officially blessed "Reserved Local CPAN Author" id
"LOCAL" as the author the distributions are added under.

To use the program, just run F<cpaninject> F<mytarball.tar.gz> to add it,
then the CPAN shell to install it (with full automatic recursive
dependency installation).

The key here being the recursive dependency installation, which you are
now able to do even for installing non-CPAN modules.

This simplifies the installation process a little, and makes things easier
on someone that just wants to install a single commercial or non-CPAN
Perl module that might have a dozen or more CPAN dependencies.

=cut

package cpaninject;

use strict;
use Params::Util '_STRING';
use CPAN::Inject;

use vars qw{$VERSION};
BEGIN {
	$VERSION = '0.11';
}





#####################################################################
# Configuration

unless ( @ARGV ) {
	error("Usage: cpaninject ./any/Perl-Distribution-1.00.tar.gz");
}

# Get the file name
my $file = _STRING(shift @ARGV);
unless ( $file ) {
	error("Did not provide a file name");
}
unless ( -f $file ) {
	error("File '$file' does not exist");
}
unless ( -r $file ) {
	error("No permissions to read '$file'");
}

# Create the injector
my $cpan = eval { CPAN::Inject->from_cpan_config };
if ( $@ ) {
	my $message = $@;
	$message =~ s/^(.+)\s+at line.+$/$1/;
	error( $message );
}

# Add the file
my $path = $cpan->add( file => $file );
message( "Injected $file ok.\n" );
message( "The following command will install it from the CPAN shell.\n" );
message( "\n" );
message( "cpan> install $path\n" );
message( "\n" );
exit(0);





#####################################################################
# Support Functions

sub message ($) {
	print ' ' . $_[0];
}

sub error (@) {
	print ' ' . join '', map { "$_\n" } ('', @_, '');
	exit(255);
}

=pod

=head1 SUPPORT

All bugs should be filed via the bug tracker at

L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPAN-Inject>

For other issues, or commercial enhancement and support, contact the author

=head1 AUTHOR

Adam Kennedy E<lt>adamk@cpan.orgE<gt>

=head1 SEE ALSO

L<CPAN::Mini::Inject>

=head1 COPYRIGHT

Copyright 2006 Adam Kennedy.

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

=cut