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<FromCPAN::Module::Name> shipped with Git itself. 20 21Usually distributors will not ship with Git's Git::FromCPAN tree at 22all, preferring to use their own packaging of CPAN modules instead. 23 24This module is only intended to be used for code shipping in the 25C<git.git> repository. Use it for anything else at your peril! 26 27=cut 28 29sub import { 30shift; 31my$caller=caller; 32my%args=@_; 33my$module=exists$args{module} ?delete$args{module} :die"BUG: Expected 'module' parameter!"; 34my$import=exists$args{import} ?delete$args{import} :die"BUG: Expected 'import' parameter!"; 35die"BUG: Too many arguments!"ifkeys%args; 36 37# Foo::Bar to Foo/Bar.pm 38my$package_pm=$module; 39$package_pm=~ s[::][/]g; 40$package_pm.='.pm'; 41 42eval{ 43require$package_pm; 441; 45}ordo{ 46my$error=$@||"Zombie Error"; 47 48my$Git_LoadCPAN_pm_path=$INC{"Git/LoadCPAN.pm"} ||die"BUG: Should have our own path from%INC!"; 49 50require File::Basename; 51my$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'!"; 52 53require File::Spec; 54my$Git_pm_FromCPAN_root= File::Spec->catdir($Git_LoadCPAN_pm_root,'..','FromCPAN'); 55die"BUG: '$Git_pm_FromCPAN_root' should be a directory!"unless-d $Git_pm_FromCPAN_root; 56 57local@INC= ($Git_pm_FromCPAN_root,@INC); 58require$package_pm; 59}; 60 61if($import) { 62no strict 'refs'; 63*{"${caller}::import"} =sub{ 64shift; 65use strict 'refs'; 66unshift@_,$module; 67goto&{"${module}::import"}; 68}; 69use strict 'refs'; 70} 71} 72 731;