Author: kane
Date: Sun Feb 25 09:12:17 2007
New Revision: 9163

Modified:
   CPANPLUS-Dist-Build/trunk/   (props changed)
   CPANPLUS-Dist-Build/trunk/Changes
   CPANPLUS-Dist-Build/trunk/lib/CPANPLUS/Dist/Build.pm
   CPANPLUS-Dist-Build/trunk/t/02_CPANPLUS-Dist-Build.t

Log:
 [EMAIL PROTECTED]:  kane | 2007-02-25 17:11:04 +0100
 * add $ENV{PERL5_CPANPLUS_IS_EXECUTING} when executing M::B->new_from_context;
   upon request of Adam Kennedy
   * add docs
   * add tests


Modified: CPANPLUS-Dist-Build/trunk/Changes
==============================================================================
--- CPANPLUS-Dist-Build/trunk/Changes   (original)
+++ CPANPLUS-Dist-Build/trunk/Changes   Sun Feb 25 09:12:17 2007
@@ -1,5 +1,10 @@
 Revision history for Perl extension CPANPLUS::Dist::Build.
 
+0.05  Sun Feb 25 17:06:38 CET 2007
+ - Set $ENV{PERL5_CPANPLUS_IS_EXECUTING} to the full path of the
+   Build.PL file when running Module::Build->new_from_context.
+   Requested by Adam Kennedy <[EMAIL PROTECTED]>.
+
 0.04  Wed Aug 16 22:00:18 CDT 2006
 
  - Address RT #13926: build_requires not included in prerequisites

Modified: CPANPLUS-Dist-Build/trunk/lib/CPANPLUS/Dist/Build.pm
==============================================================================
--- CPANPLUS-Dist-Build/trunk/lib/CPANPLUS/Dist/Build.pm        (original)
+++ CPANPLUS-Dist-Build/trunk/lib/CPANPLUS/Dist/Build.pm        Sun Feb 25 
09:12:17 2007
@@ -192,6 +192,11 @@
 C<new_from_context> method, and establishing any prerequisites this
 distribution has.
 
+When running C<< Module::Build->new_from_context >>, the environment 
+variable C<PERL5_CPANPLUS_IS_EXECUTING> will be set to the full path 
+of the C<Build.PL> that is being executed. This enables any code inside
+the C<Build.PL> to know that it is being installed via CPANPLUS.
+
 After a succcesfull C<prepare> you may call C<create> to create the
 distribution, followed by C<install> to actually install it.
 
@@ -268,7 +273,11 @@
     RUN: {
         # Wrap the exception that may be thrown here (should likely be
         # done at a much higher level).
-        my $mb = eval { Module::Build->new_from_context( %buildflags ) };
+        my $mb = eval { 
+            my $env = ENV_CPANPLUS_IS_EXECUTING;
+            local $ENV{$env} = BUILD_PL->( $dir );
+            Module::Build->new_from_context( %buildflags ) 
+        };
         if( !$mb or $@ ) {
             error(loc("Could not create Module::Build object: %1","$@"));
             $fail++; last RUN;

Modified: CPANPLUS-Dist-Build/trunk/t/02_CPANPLUS-Dist-Build.t
==============================================================================
--- CPANPLUS-Dist-Build/trunk/t/02_CPANPLUS-Dist-Build.t        (original)
+++ CPANPLUS-Dist-Build/trunk/t/02_CPANPLUS-Dist-Build.t        Sun Feb 25 
09:12:17 2007
@@ -42,6 +42,15 @@
 my $CB      = CPANPLUS::Backend->new;
 my $Conf    = $CB->configure_object;
 
+
+### create a fake object, so we don't use the actual module tree
+my $Mod = CPANPLUS::Module::Fake->new(
+                module  => 'Foo::Bar',
+                path    => 'src',
+                author  => CPANPLUS::Module::Author::Fake->new,
+                package => 'Foo-Bar-0.01.tar.gz',
+            );
+
 $Conf->set_conf( base       => 'dummy-cpanplus' );
 $Conf->set_conf( dist_type  => '' );
 $Conf->set_conf( verbose    => $Verbose );
@@ -76,14 +85,7 @@
 
 while( my($path,$need_cc) = each %Map ) {
 
-    ### create a fake object, so we don't use the actual module tree
-    my $mod = CPANPLUS::Module::Fake->new(
-                    module  => 'Foo::Bar',
-                    path    => 'src',
-                    author  => CPANPLUS::Module::Author::Fake->new,
-                    package => 'Foo-Bar-0.01.tar.gz',
-                );
-
+    my $mod = $Mod->clone;
     ok( $mod,                   "Module object created for '$path'" );        
                 
     ### set the fetch location -- it's local
@@ -173,6 +175,39 @@
     $Utils->_rmdir( dir => $Conf->get_conf('base') );
 }
 
+### test ENV setting while running Build.PL code
+{   ### use print() not die() -- we're redirecting STDERR in tests!
+    my $env     = ENV_CPANPLUS_IS_EXECUTING;
+    my $clone   = $Mod->clone;
+    
+    ok( $clone,                 'Testing ENV settings $dist->prepare' );
+    
+    $clone->status->fetch( File::Spec->catfile($Src, 'noxs', $clone->package) 
);
+    ok( $clone->extract,        '   Files extracted' );
+    
+    ### write our own Build.PL file    
+    my $build_pl = BUILD_PL->( $clone->status->extract );
+    {   my $fh   = OPEN_FILE->( $build_pl, '>' );
+        print $fh "die qq[ENV=\$ENV{$env}\n];";
+        close $fh;
+    }
+    ok( -e $build_pl,           "   File exists" );
+
+    ### clear errors    
+    CPANPLUS::Error->flush;
+
+    ### since we're die'ing in the Build.PL, do a local *STDERR,
+    ### so we dont spam the result through the test -- this is expected
+    ### behaviour after all.
+    my $rv = do { local *STDERR; $clone->prepare( force => 1 ) };
+    ok( !$rv,                   '   $mod->prepare failed' );
+
+    my $re = quotemeta( $build_pl );
+    like( CPANPLUS::Error->stack_as_string, qr/ENV=$re/,
+                                "   \$ENV $env set correctly during 
execution");
+}    
+
+
 sub find_module {
   my $module = shift;
 
@@ -193,6 +228,7 @@
   return;
 }
 
+
 # Local variables:
 # c-indentation-style: bsd
 # c-basic-offset: 4

Reply via email to