From 73e91d5ab26c8e505f47d63fdd32c83a208f60d9 Mon Sep 17 00:00:00 2001 From: "James E. Keenan" Date: Sun, 6 Feb 2011 11:38:11 +0100 Subject: [PATCH] Move TidyType() to Utilities::tidy_type() Create test file for it. --- MANIFEST | 1 + dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm | 25 +++---------- .../lib/ExtUtils/ParseXS/Utilities.pm | 41 ++++++++++++++++++++++ dist/ExtUtils-ParseXS/t/103-tidy_type.t | 23 ++++++++++++ 4 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 dist/ExtUtils-ParseXS/t/103-tidy_type.t diff --git a/MANIFEST b/MANIFEST index 39a4a6e..da55788 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2981,6 +2981,7 @@ dist/ExtUtils-ParseXS/t/002-more.t Extended ExtUtils::ParseXS testing dist/ExtUtils-ParseXS/t/003-usage.t ExtUtils::ParseXS tests dist/ExtUtils-ParseXS/t/101-standard_typemap_locations.t ExtUtils::ParseXS tests dist/ExtUtils-ParseXS/t/102-trim_whitespace.t ExtUtils::ParseXS tests +dist/ExtUtils-ParseXS/t/103-tidy_type.t ExtUtils::ParseXS tests dist/ExtUtils-ParseXS/t/lib/IncludeTester.pm ExtUtils::ParseXS testing utility dist/ExtUtils-ParseXS/t/typemap Standard typemap for controlled testing dist/ExtUtils-ParseXS/t/XSInclude.xsh Test file for ExtUtils::ParseXS tests diff --git a/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm b/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm index 79cdd9b..7ca75b1 100644 --- a/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm +++ b/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm @@ -10,6 +10,7 @@ use Symbol; use ExtUtils::ParseXS::Utilities qw( standard_typemap_locations trim_whitespace + tidy_type ); our (@ISA, @EXPORT_OK, $VERSION); @@ -175,7 +176,7 @@ sub process_file { next if /^$/ or /^#/; my($type,$kind, $proto) = /^\s*(.*?\S)\s+(\S+)\s*($proto_re*)\s*$/ or warn("Warning: File '$typemap' Line $. '$line' TYPEMAP entry needs 2 or 3 columns\n"), next; - $type = TidyType($type); + $type = tidy_type($type); $type_kind{$type} = $kind; # prototype defaults to '$' $proto = "\$" unless $proto; @@ -472,7 +473,7 @@ EOF } # extract return type, function name and arguments - ($ret_type) = TidyType($_); + ($ret_type) = tidy_type($_); $RETVAL_no_return = 1 if $ret_type =~ s/^NO_OUTPUT\s+//; # Allow one-line ANSI-like declaration @@ -1091,22 +1092,6 @@ EOF sub errors { $errors } -sub TidyType { - local ($_) = @_; - - # rationalise any '*' by joining them into bunches and removing whitespace - s#\s*(\*+)\s*#$1#g; - s#(\*+)# $1 #g; - - # change multiple whitespace into a single space - s/\s+/ /g; - - # trim leading & trailing whitespace - trim_whitespace($_); - - $_; -} - # Input: ($_, @line) == unparsed input. # Output: ($_, @line) == (rest of line, following lines). # Return: the matched keyword if found, otherwise 0 @@ -1815,7 +1800,7 @@ sub generate_init { local($ntype); local($tk); - $type = TidyType($type); + $type = tidy_type($type); blurt("Error: '$type' not in typemap"), return unless defined($type_kind{$type}); @@ -1894,7 +1879,7 @@ sub generate_output { local($argoff) = $num - 1; local($ntype); - $type = TidyType($type); + $type = tidy_type($type); if ($type =~ /^array\(([^,]*),(.*)\)/) { print "\t$arg = sv_newmortal();\n"; print "\tsv_setpvn($arg, (char *)$var, $2 * sizeof($1));\n"; diff --git a/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Utilities.pm b/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Utilities.pm index 66b97cb..105568f 100644 --- a/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Utilities.pm +++ b/dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Utilities.pm @@ -8,6 +8,7 @@ our (@ISA, @EXPORT_OK); @EXPORT_OK = qw( standard_typemap_locations trim_whitespace + tidy_type ); =head1 NAME @@ -19,6 +20,7 @@ ExtUtils::ParseXS::Utilities - Subroutines used with ExtUtils::ParseXS use ExtUtils::ParseXS::Utilities qw( standard_typemap_locations trim_whitespace + tidy_type ); =head1 SUBROUTINES @@ -137,4 +139,43 @@ sub trim_whitespace { $_[0] =~ s/^\s+|\s+$//go; } +=head2 C + +=over 4 + +=item * Purpose + +Rationalize any asterisks (C<*>) by joining them into bunches, removing +interior whitespace, then trimming leading and trailing whitespace. + +=item * Arguments + + ($ret_type) = tidy_type($_); + +String to be cleaned up. + +=item * Return Value + +String cleaned up. + +=back + +=cut + +sub tidy_type { + local ($_) = @_; + + # rationalise any '*' by joining them into bunches and removing whitespace + s#\s*(\*+)\s*#$1#g; + s#(\*+)# $1 #g; + + # change multiple whitespace into a single space + s/\s+/ /g; + + # trim leading & trailing whitespace + trim_whitespace($_); + + $_; +} + 1; diff --git a/dist/ExtUtils-ParseXS/t/103-tidy_type.t b/dist/ExtUtils-ParseXS/t/103-tidy_type.t new file mode 100644 index 0000000..a043383 --- /dev/null +++ b/dist/ExtUtils-ParseXS/t/103-tidy_type.t @@ -0,0 +1,23 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Test::More tests => 3; +use lib qw( lib ); +use ExtUtils::ParseXS::Utilities qw( + tidy_type +); + +my $input; + +$input = ' * ** '; +is( tidy_type($input), '***', + "Got expected value for '$input'" ); + +$input = ' * ** '; +is( tidy_type($input), '***', + "Got expected value for '$input'" ); + +$input = ' * ** foobar * '; +is( tidy_type($input), '*** foobar *', + "Got expected value for '$input'" ); + -- 2.7.4