[svn:parrot] r37335 - in branches/install_tools: lib/Parrot t/tools/install tools/dev

jkeenan at svn.parrot.org jkeenan at svn.parrot.org
Wed Mar 11 23:59:41 UTC 2009


Author: jkeenan
Date: Wed Mar 11 23:59:41 2009
New Revision: 37335
URL: https://trac.parrot.org/parrot/changeset/37335

Log:
In Parrot::Install, begin to add documentation for individual subroutines.
List subroutines in the order in which they are called in install programs.
Subroutines are now explicitly imported so they don't need to be fully
qualified.

Modified:
   branches/install_tools/lib/Parrot/Install.pm
   branches/install_tools/t/tools/install/01-install_files.t
   branches/install_tools/tools/dev/install_files.pl

Modified: branches/install_tools/lib/Parrot/Install.pm
==============================================================================
--- branches/install_tools/lib/Parrot/Install.pm	Wed Mar 11 23:29:07 2009	(r37334)
+++ branches/install_tools/lib/Parrot/Install.pm	Wed Mar 11 23:59:41 2009	(r37335)
@@ -4,62 +4,62 @@
 use warnings;
 use File::Basename qw(dirname);
 use File::Copy;
+use File::Spec;
 use base qw( Exporter );
 our @EXPORT_OK = qw(
-    install_files
-    create_directories
     lines_to_files
+    create_directories
+    install_files
 );
 
-# Install the mentioned files into the appropriate locations
-sub install_files {
-    my($destdir, $dryrun, @files) = @_;
-    my($src, $dest, $mode);
+#################### DOCUMENTATION ####################
 
-    print("Installing ...\n");
-    foreach ( @files ) {
-        next unless $_;
-        ( $src, $dest ) = @$_;
-        $dest = $destdir . $dest;
-        if ( $dryrun ) {
-            print "$src -> $dest\n";
-            next;
-        }
-        else {
-            next unless -e $src;
-            next if $^O eq 'cygwin' and -e "$src.exe"; # stat works, copy not
-            copy( $src, $dest ) or die "copy $src to $dest: $!\n";
-            print "$dest\n";
-        }
-        $mode = ( stat($src) )[2];
-        chmod $mode, $dest;
-    }
-}
+=head1 NAME
 
-# Created the directories passed in
-sub create_directories {
-    my($destdir, $directories) = @_;
-    my($dir, @dirs);
+Parrot::Install - Functionality for installation programs
 
-    for $dir ( map { $destdir . $_ } keys %$directories ) {
-        unless ( -d $dir ) {
+=head1 SYNOPSIS
 
-            # Make full path to the directory $dir
-            while ( !-d $dir ) {    # Scan up to nearest existing ancestor
-                unshift @dirs, $dir;
-                $dir = dirname($dir);
-            }
-            foreach (@dirs) {
-                -d or mkdir( $_, 0777 ) or die "mkdir $_: $!\n";
-            }
-        }
-    }
-}
+    use Parrot::Install qw(
+        install_files
+        create_directories
+        lines_to_files
+    );
+
+=head1 DESCRIPTION
+
+This module exports on demand only three subroutines used in the Parrot
+installation programs F<tools/dev/install_files.pl> and
+F<tools/dev/install_dev_files.pl>.  The subroutines are tested by tests found
+in F<t/tools/install/>.
+
+=head1 SUBROUTINES
+
+=head2 C<lines_to_files()>
+
+B<Purpose:> Suck in the lines from the mentioned manifests, and turn them into
+file locations.
+
+B<Arguments:> List of five scalars.
+
+    ($files, $installable_exe, $directories) =
+        lines_to_files(
+            \%metatransforms,
+            \%othertransforms,
+            \@manifests,
+            \%options,
+            $parrotdir,
+        );
+
+B<Return Value:> List of three scalars.
+
+B<Comment:>
+
+=cut
 
-# Suck in the lines from the mentioned manifests,
-# and turn them into file locations.
 sub lines_to_files {
-    my($metatransforms, $othertransforms, $manifests, $options, $parrotdir) = @_;
+    my ($metatransforms, $othertransforms, $manifests, $options, $parrotdir)
+        = @_;
     my @files;
     my @installable_exe;
     my %directories;
@@ -150,6 +150,87 @@
     return(\@files, \@installable_exe, \%directories);
 }
 
+=head2 C<create_directories()>
+
+B<Purpose:> Creates the directories passed in.
+
+B<Arguments:>  Two scalar arguments.
+
+    create_directories(
+        $destination_directory,
+        $directories_hash_ref,
+    );
+
+B<Return Value:>  True value.
+
+B<Comment:>
+
+=cut
+
+sub create_directories {
+    my($destdir, $directories) = @_;
+    my($dir, @dirs);
+
+    for $dir ( map { $destdir . $_ } keys %$directories ) {
+        unless ( -d $dir ) {
+
+            # Make full path to the directory $dir
+            while ( !-d $dir ) {    # Scan up to nearest existing ancestor
+                unshift @dirs, $dir;
+                $dir = dirname($dir);
+            }
+            foreach (@dirs) {
+                -d or mkdir( $_, 0777 ) or die "mkdir $_: $!\n";
+            }
+        }
+    }
+    return 1;
+}
+
+=head2 C<install_files()>
+
+B<Purpose:> Install the mentioned files into the appropriate locations.
+
+    install_files(
+        $destination_directory,
+        $dry_run_option,
+        @list_of_files_and_executables,
+    );
+
+B<Arguments:>  Takes two scalar arguments, followed by a list.  (B<NOTE:>  We
+must change this to three scalars, where the last is an array ref.)
+
+B<Return Value:>  True value.
+
+B<Comment:>
+
+=cut
+
+sub install_files {
+    my($destdir, $dryrun, @files) = @_;
+    my($src, $dest, $mode);
+
+    print("Installing ...\n");
+    foreach ( @files ) {
+        next unless $_;
+        ( $src, $dest ) = @$_;
+        $dest = $destdir . $dest;
+        if ( $dryrun ) {
+            print "$src -> $dest\n";
+            next;
+        }
+        else {
+            next unless -e $src;
+            next if $^O eq 'cygwin' and -e "$src.exe"; # stat works, copy not
+            copy( $src, $dest ) or die "copy $src to $dest: $!\n";
+            print "$dest\n";
+        }
+        $mode = ( stat($src) )[2];
+        chmod $mode, $dest;
+    }
+    return 1;
+}
+
 1;
 
 # Local Variables:

Modified: branches/install_tools/t/tools/install/01-install_files.t
==============================================================================
--- branches/install_tools/t/tools/install/01-install_files.t	Wed Mar 11 23:29:07 2009	(r37334)
+++ branches/install_tools/t/tools/install/01-install_files.t	Wed Mar 11 23:59:41 2009	(r37335)
@@ -8,12 +8,14 @@
 
 use Test::More tests =>  1;
 use Carp;
+use File::Temp qw( tempdir );
 use lib qw( lib );
 use Parrot::Install qw(
     install_files
     create_directories
     lines_to_files
 );
+use IO::CaptureOutput qw( capture );
 
 pass("Completed all tests in $0");
 

Modified: branches/install_tools/tools/dev/install_files.pl
==============================================================================
--- branches/install_tools/tools/dev/install_files.pl	Wed Mar 11 23:29:07 2009	(r37334)
+++ branches/install_tools/tools/dev/install_files.pl	Wed Mar 11 23:59:41 2009	(r37335)
@@ -213,12 +213,12 @@
     },
 );
 
-my($files, $installable_exe, $directories) = Parrot::Install::lines_to_files(
+my($files, $installable_exe, $directories) = lines_to_files(
     \%metatransforms, \%othertransforms, \@manifests, \%options, $parrotdir
 );
 
 unless ( $options{'dry-run'} ) {
-    Parrot::Install::create_directories($options{destdir}, $directories);
+    create_directories($options{destdir}, $directories);
 }
 
 # TT #347
@@ -249,7 +249,10 @@
     }
 }
 
-Parrot::Install::install_files($options{destdir}, $options{'dry-run'}, @$files, @$installable_exe);
+install_files(
+    $options{destdir}, $options{'dry-run'}, @$files, @$installable_exe
+);
+
 print "Finished install_files.pl\n";
 
 # Local Variables:


More information about the parrot-commits mailing list