Author: dagolden
Date: Fri Feb  6 13:06:58 2009
New Revision: 12479

Modified:
   Module-Build/trunk/   (props changed)
   Module-Build/trunk/Changes
   Module-Build/trunk/lib/Module/Build.pm
   Module-Build/trunk/lib/Module/Build/API.pod
   Module-Build/trunk/lib/Module/Build/Base.pm

Log:
Added 'prereq_data' action to dump prequisites as a Perl data structure


Modified: Module-Build/trunk/Changes
==============================================================================
--- Module-Build/trunk/Changes  (original)
+++ Module-Build/trunk/Changes  Fri Feb  6 13:06:58 2009
@@ -2,6 +2,11 @@
 
 0.31_03 - 
 
+ Enhancements
+ - added a "prereq_data" action that prints a Perl data structure of
+   all prerequisites; can be loaded by external tools using eval()
+   [David Golden]
+
 0.31_02 - Tue Jan 27 09:16:43 PST 2009
 
  Other

Modified: Module-Build/trunk/lib/Module/Build.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build.pm      (original)
+++ Module-Build/trunk/lib/Module/Build.pm      Fri Feb  6 13:06:58 2009
@@ -496,6 +496,14 @@
 output, so you can supply C<tar> and/or C<gzip> parameters to affect
 the result.
 
+=item prereq_data
+
+[version 0.32]
+
+This action prints out a Perl data structure of all prerequsites and the 
versions
+required.  The output can be loaded again using C<eval()>.  This can be useful 
for
+external tools that wish to query a Build script for prerequisites.
+
 =item prereq_report
 
 [version 0.28]

Modified: Module-Build/trunk/lib/Module/Build/API.pod
==============================================================================
--- Module-Build/trunk/lib/Module/Build/API.pod (original)
+++ Module-Build/trunk/lib/Module/Build/API.pod Fri Feb  6 13:06:58 2009
@@ -1548,6 +1548,18 @@
     }
   }
 
+=item prereq_data()
+
+[version 0.32]
+
+Returns a reference to a hash describing all prerequisites.  The keys of the
+hash will the various prerequisite types ('requires', 'build_requires',
+'configure_requires', 'recommends', or 'conflicts') and the values will
+references to hashes of module names and version numbers.  Only prerequisites
+types that are defined will be included.  The C<prereq_data> action is just a
+thin wrapper around the C<prereq_data()> method and dumps the hash as a string
+that can be loaded using C<eval()>.
+
 =item prereq_report()
 
 [version 0.28]

Modified: Module-Build/trunk/lib/Module/Build/Base.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build/Base.pm (original)
+++ Module-Build/trunk/lib/Module/Build/Base.pm Fri Feb  6 13:06:58 2009
@@ -2054,15 +2054,25 @@
   $self->log_info( $self->prereq_report );
 }
 
-sub prereq_report {
+sub ACTION_prereq_data {
+  my $self = shift;
+  $self->log_info( Module::Build::Dumper->_data_dump( $self->prereq_data ) );
+}
+
+sub prereq_data {
   my $self = shift;
   my @types = @{ $self->prereq_action_types };
-  my $info = { map { $_ => $self->$_() } @types };
+  my $info = { map { $_ => $self->$_() } grep { %{$self->$_()} } @types };
+  return $info;
+}
+
+sub prereq_report {
+  my $self = shift;
+  my $info = $self->prereq_data;
 
   my $output = '';
-  foreach my $type (@types) {
+  foreach my $type (keys %$info) {
     my $prereqs = $info->{$type};
-    next unless %$prereqs;
     $output .= "\n$type:\n";
     my $mod_len = 2;
     my $ver_len = 4;

Reply via email to