[svn:parrot] r37661 - in trunk: . lib/Parrot/Pmc2c t/tools/pmc2cutils
coke at svn.parrot.org
coke at svn.parrot.org
Tue Mar 24 02:26:16 UTC 2009
Author: coke
Date: Tue Mar 24 02:26:16 2009
New Revision: 37661
URL: https://trac.parrot.org/parrot/changeset/37661
Log:
[cage] Remove (overkill) "open_file" utility method. 'open' works fine,
esp. when you 'use Fatal qw(open);'
Deleted:
trunk/t/tools/pmc2cutils/07-open_file.t
Modified:
trunk/MANIFEST
trunk/lib/Parrot/Pmc2c/UtilFunctions.pm
trunk/t/tools/pmc2cutils/01-pmc2cutils.t
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST Tue Mar 24 01:41:52 2009 (r37660)
+++ trunk/MANIFEST Tue Mar 24 02:26:16 2009 (r37661)
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Mon Mar 23 20:21:49 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Tue Mar 24 02:18:09 2009 UT
#
# See tools/dev/install_files.pl for documentation on the
# format of this file.
@@ -2038,7 +2038,6 @@
t/tools/pmc2cutils/03-dump_vtable.t [test]
t/tools/pmc2cutils/04-dump_pmc.t [test]
t/tools/pmc2cutils/05-gen_c.t [test]
-t/tools/pmc2cutils/07-open_file.t [test]
t/tools/pmc2cutils/08-pmc-pm.t [test]
t/tools/pmc2cutils/README []doc
tools/build/addopstags.pl []
Modified: trunk/lib/Parrot/Pmc2c/UtilFunctions.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/UtilFunctions.pm Tue Mar 24 01:41:52 2009 (r37660)
+++ trunk/lib/Parrot/Pmc2c/UtilFunctions.pm Tue Mar 24 02:26:16 2009 (r37661)
@@ -4,9 +4,12 @@
package Parrot::Pmc2c::UtilFunctions;
use strict;
use warnings;
+
+use Fatal qw(open close);
+
use base qw( Exporter );
our @EXPORT_OK = qw( count_newlines return_statement dont_edit dynext_load_code
- c_code_coda slurp spew splat open_file filename escape_filename
+ c_code_coda slurp spew splat filename escape_filename
args_from_parameter_list
passable_args_from_parameter_list
);
@@ -256,48 +259,9 @@
EOC
}
-=head3 C<open_file()>
-
- $fh = open_file( "<", $file );
-
-B<Purpose:> Utility subroutine.
-
-B<Arguments:> List of scalars: two required, one optional.
-
-=over 4
-
-=item * action
-
-String holding action/direction desired: C<E<lt>> for
-reading or C<E<gt>E<gt>> for writing or appending.
-
-=item * filename
-
-String holding name of file to be opened.
-
-=back
-
-B<Return Values:> Filehandle to file so opened.
-
-B<Comment:> Called within C<dump_vtable()>, C<read_dump()>, and C<dump_pmc()>.
-
-=cut
-
-sub open_file {
- my ( $direction, $filename ) = @_;
-
- my $verbose = 0;
- my $actions_descriptions = { '<' => 'Reading', '>>' => "Appending", '>' => "Writing" };
- my $action = $actions_descriptions->{$direction} || "Unknown";
- print "$action $filename\n" if $verbose;
-
- open my $fh, $direction, $filename or die "$action $filename: $!\n";
- return $fh;
-}
-
sub slurp {
my ($filename) = @_;
- my $fh = open_file( '<', $filename );
+ open my $fh, '<', $filename;
my $data = do { local $/; <$fh> };
close $fh;
return $data;
@@ -305,15 +269,15 @@
sub spew {
my ( $filename, $data ) = @_;
- my $fh = open_file( '>', $filename );
- print $fh $data;
+ open my $fh, '>', $filename;
+ print {$fh} $data;
close $fh;
}
sub splat {
my ( $filename, $data ) = @_;
- my $fh = open_file( '>>', $filename );
- print $fh $data;
+ open my $fh, '>>', $filename;
+ print {$fh} $data;
close $fh;
}
Modified: trunk/t/tools/pmc2cutils/01-pmc2cutils.t
==============================================================================
--- trunk/t/tools/pmc2cutils/01-pmc2cutils.t Tue Mar 24 01:41:52 2009 (r37660)
+++ trunk/t/tools/pmc2cutils/01-pmc2cutils.t Tue Mar 24 02:26:16 2009 (r37661)
@@ -19,7 +19,7 @@
}
unshift @INC, qq{$topdir/lib};
}
-use Test::More tests => 20;
+use Test::More tests => 19;
use_ok('Parrot::Pmc2c::Pmc2cMain');
@@ -41,8 +41,6 @@
can_ok( $self, q{gen_c} );
can_ok( $self, q{dump_pmc} );
-can_ok( 'Parrot::Pmc2c::UtilFunctions', q{open_file} );
-
can_ok( 'Parrot::Pmc2c::Parser', q{parse_pmc} );
can_ok( 'Parrot::Pmc2c::Parser', q{parse_flags} );
can_ok( 'Parrot::Pmc2c::Parser', q{parse_method_attrs} );
Deleted: trunk/t/tools/pmc2cutils/07-open_file.t
==============================================================================
--- trunk/t/tools/pmc2cutils/07-open_file.t Tue Mar 24 02:26:16 2009 (r37660)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,128 +0,0 @@
-#! perl
-# Copyright (C) 2006-2007, Parrot Foundation.
-# $Id$
-# 07-open_file.t
-
-use strict;
-use warnings;
-
-BEGIN {
- use FindBin qw($Bin);
- use Cwd qw(cwd realpath);
- realpath($Bin) =~ m{^(.*\/parrot)\/[^/]*\/[^/]*\/[^/]*$};
- our $topdir = $1;
- if ( defined $topdir ) {
- print "\nOK: Parrot top directory located\n";
- }
- else {
- $topdir = realpath($Bin) . "/../../..";
- }
- unshift @INC, qq{$topdir/lib};
-}
-use Test::More tests => 13;
-use File::Basename;
-use File::Copy;
-use FindBin;
-use Data::Dumper;
-use_ok('Parrot::Pmc2c::UtilFunctions');
-use_ok('Cwd');
-use_ok( 'File::Temp', qw| tempdir | );
-
-my ( %opt, @include, @args );
-my $dump_file;
-my $self;
-my $rv;
-my $cwd = cwd();
-
-my $file = q{sample.txt};
-my ($direction);
-my $fh;
-
-{
- my $tdir = tempdir( CLEANUP => 1 );
- ok( chdir $tdir, 'changed to temp directory for testing' );
-
- ok( create_test_file($file), "test file created" );
-
- $direction = '<';
- ok( $fh = Parrot::Pmc2c::UtilFunctions::open_file( $direction, $file ),
- "file opened for reading" );
- close $fh or die "Unable to close handle to test file";
-
- $direction = '>';
- ok( $fh = Parrot::Pmc2c::UtilFunctions::open_file( $direction, $file ),
- "file opened for writing" );
- close $fh or die "Unable to close handle to test file";
-
- $direction = '>>';
- ok( $fh = Parrot::Pmc2c::UtilFunctions::open_file( $direction, $file ),
- "file opened for appending" );
- close $fh or die "Unable to close handle to test file";
-
- ok( chdir $cwd, "changed back to original directory" );
-}
-
-# failure case: nonexistent file
-{
- my $tdir = tempdir( CLEANUP => 1 );
- ok( chdir $tdir, 'changed to temp directory for testing' );
-
- my ( $currfh, $msg, $msgfh );
-
- $direction = '<';
- eval { $fh = Parrot::Pmc2c::UtilFunctions::open_file( $direction, $file ); };
- like( $@, qr/^Reading sample.txt/, "correctly failed to read nonexistent file" );
-
- ok( chdir $cwd, "changed back to original directory" );
-}
-
-pass("Completed all tests in $0");
-
-sub create_test_file {
- my $filename = shift;
- open my $FH, '>', $filename or die "Unable to create test file: $!";
- close $FH or die "Unable to close test file: $!";
- return 1;
-}
-
-################### DOCUMENTATION ###################
-
-=head1 NAME
-
-07-open_file.t - test C<Parrot::Pmc2c::UtilFunctions::open_file()>
-
-=head1 SYNOPSIS
-
- % prove t/tools/pmc2cutils/07-open_file.t
-
-=head1 DESCRIPTION
-
-The files in this directory test the publicly callable methods of
-F<lib/Parrot/Pmc2c/Pmc2cMain.pm>. By doing so, they test the functionality
-of the F<pmc2c.pl> utility. That functionality has largely been extracted
-into the methods of F<Pmc2cMain.pm>.
-
-F<07-open_file.t> tests the C<Parrot::Pmc2c::UtilFunctions::open_file()> subroutine.
-This subroutine is I<not> called F<make> but is called by methods which are
-called by F<make>.
-
-So as not to pollute the Parrot build directories with files created
-during the testing process, all functions which create or modify
-files should be called within a temporary directory.
-
-=head1 AUTHOR
-
-James E Keenan
-
-=head1 SEE ALSO
-
-Parrot::Pmc2c, F<pmc2c.pl>.
-
-=cut
-
-# Local Variables:
-# mode: cperl
-# cperl-indent-level: 4
-# fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4:
More information about the parrot-commits
mailing list