1package Git::LoadCPAN; 2use5.008; 3use strict; 4use warnings; 5 6=head1 NAME 7 8Git::LoadCPAN - Wrapper for loading modules from the CPAN (OS) or Git's own copy 9 10=head1 DESCRIPTION 11 12The Perl code in Git depends on some modules from the CPAN, but we 13don't want to make those a hard requirement for anyone building from 14source. 15 16Therefore the L<Git::LoadCPAN> namespace shipped with Git contains 17wrapper modules like C<Git::LoadCPAN::Module::Name> that will first 18attempt to load C<Module::Name> from the OS, and if that doesn't work 19will fall back on C<Git::FromCPAN::Module::Name> shipped with Git 20itself. 21 22Usually distributors will not ship with Git's Git::FromCPAN tree at 23all, preferring to use their own packaging of CPAN modules instead. 24 25This module is only intended to be used for code shipping in the 26C<git.git> repository. Use it for anything else at your peril! 27 28=cut 29 30sub import { 31shift; 32my$caller=caller; 33my%args=@_; 34my$module=exists$args{module} ?delete$args{module} :die"BUG: Expected 'module' parameter!"; 35my$import=exists$args{import} ?delete$args{import} :die"BUG: Expected 'import' parameter!"; 36die"BUG: Too many arguments!"ifkeys%args; 37 38# Foo::Bar to Foo/Bar.pm 39my$package_pm=$module; 40$package_pm=~ s[::][/]g; 41$package_pm.='.pm'; 42 43eval{ 44require$package_pm; 451; 46}ordo{ 47my$error=$@||"Zombie Error"; 48 49my$Git_LoadCPAN_pm_path=$INC{"Git/LoadCPAN.pm"} ||die"BUG: Should have our own path from%INC!"; 50 51require File::Basename; 52my$Git_LoadCPAN_pm_root= File::Basename::dirname($Git_LoadCPAN_pm_path) ||die"BUG: Can't figure out lib/Git dirname from '$Git_LoadCPAN_pm_path'!"; 53 54require File::Spec; 55my$Git_pm_FromCPAN_root= File::Spec->catdir($Git_LoadCPAN_pm_root,'FromCPAN'); 56die"BUG: '$Git_pm_FromCPAN_root' should be a directory!"unless-d $Git_pm_FromCPAN_root; 57 58local@INC= ($Git_pm_FromCPAN_root,@INC); 59require$package_pm; 60}; 61 62if($import) { 63no strict 'refs'; 64*{"${caller}::import"} =sub{ 65shift; 66use strict 'refs'; 67unshift@_,$module; 68goto&{"${module}::import"}; 69}; 70use strict 'refs'; 71} 72} 73 741;