From: Ken Youens-Clark Date: Fri, 9 May 2003 16:54:03 +0000 (+0000) Subject: Added oft-used "parse_list_arg" sub for Schema classes. X-Git-Tag: v0.02~130 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=118bb73f72e2483a02833954d442dbf26f7ac1c7;p=dbsrgits%2FSQL-Translator.git Added oft-used "parse_list_arg" sub for Schema classes. --- diff --git a/lib/SQL/Translator/Utils.pm b/lib/SQL/Translator/Utils.pm index 87ec225..88fe399 100644 --- a/lib/SQL/Translator/Utils.pm +++ b/lib/SQL/Translator/Utils.pm @@ -1,7 +1,7 @@ package SQL::Translator::Utils; # ---------------------------------------------------------------------- -# $Id: Utils.pm,v 1.3 2003-04-25 11:44:20 dlc Exp $ +# $Id: Utils.pm,v 1.4 2003-05-09 16:54:03 kycl4rk Exp $ # ---------------------------------------------------------------------- # Copyright (C) 2003 darren chamberlain # @@ -28,7 +28,9 @@ use Exporter; $VERSION = 1.00; $DEFAULT_COMMENT = '-- '; -@EXPORT_OK = qw(debug normalize_name header_comment $DEFAULT_COMMENT); +@EXPORT_OK = qw( + debug normalize_name header_comment parse_list_arg $DEFAULT_COMMENT +); # ---------------------------------------------------------------------- # debug(@msg) @@ -68,7 +70,7 @@ sub debug { } } - +# ---------------------------------------------------------------------- sub normalize_name { my $name = shift; @@ -89,6 +91,7 @@ sub normalize_name { return $name; } +# ---------------------------------------------------------------------- sub header_comment { my $producer = shift || caller; my $comment_char = shift; @@ -112,9 +115,19 @@ HEADER_COMMENT return $header_comment; } +# ---------------------------------------------------------------------- +sub parse_list_arg { + return UNIVERSAL::isa( $_[0], 'ARRAY' ) + ? shift + : [ map { s/^\s+|\s+$//g; $_ } map { split /,/ } @_ ] + ; +} + 1; -__END__ +# ---------------------------------------------------------------------- + +=pod =head1 NAME @@ -205,8 +218,28 @@ produces: Note the gratuitous spacing. +=head2 parse_list_arg + +Takes a string, list or arrayref (all of which could contain +comma-separated values) and returns an array reference of the values. +All of the following will return equivalent values: + + parse_list_arg('id'); + parse_list_arg('id', 'name'); + parse_list_arg( 'id, name' ); + parse_list_arg( [ 'id', 'name' ] ); + parse_list_arg( qw[ id name ] ); + =head2 $DEFAULT_COMMENT This is the default comment string, '-- ' by default. Useful for C. +=head1 AUTHORS + +Darren Chamberlain Edarren@cpan.orgE, +Ken Y. Clark Ekclark@cpan.orgE. + +=cut + +=cut