1package Business::EDI::Generator; 2 3# Common functions for the scripts used to generate class modules. 4 5use strict; 6use warnings; 7 8our $VERSION = 0.01; 9 10use Exporter::Easy ( 11 EXPORT => [qw( :all )], 12 TAGS => [ 13 all => [qw( next_line next_chunk quotify safename )], 14 ], 15); 16 17sub next_line { 18 my $line = <STDIN>; 19 defined($line) or return; 20 $line =~ s/\s*$//; # kill trailing spaces 21 $line .= "\n"; # replacing ^M DOS line endings 22 if (@_ and $_[0]) { 23 $line = next_line() while ($line !~ /\S/); # skip empties 24 } 25 return $line; 26} 27 28sub next_chunk { 29 my $chunk = ''; 30 my $piece; 31 while ($piece = next_line) { # need to get back a blank line (no '1' for next_line()) 32 defined($piece) or last; 33 $piece =~ /\S/ or last; # blank means we're done 34 $piece =~ s/^\s*//; # kill leading spaces 35 $piece =~ s/\s*$//; # kill trailing spaces 36 $chunk .= ' ' if $chunk; # add a space, if necessary, to keep words from runningtogether. 37 $chunk .= $piece; 38 } 39 return $chunk; 40} 41 42sub quotify { 43 my $string = shift or return ''; 44 $string =~ /'/ or return "'$string'" ; # easiest case, safe for single quotes 45 $string =~ /"/ or return '"' . $string . '"'; # contains single quotes, but no doubles. use doubles 46 $string =~ s/'/\\'/g; # otherwise it has both, so we'll escape the singles 47 return "'$string'" ; 48} 49 50sub safename { 51 my $string = shift; 52 $string =~ s/[^A-z0-9]//; # no weird charaters (e.g. punctuation) in filenames 53 return $string; 54} 55 561; 57 58