PERL CVS PARROT 6 CVS COMMIT PARROT T LIBRARY GETOPT LONG T
Date: 20 Feb 2005 10:28:14 -0000

Subject: cvs commit: parrot/t/library getopt_long.t
From: bernhard@no-spam (Bernhard Schmalhofer)

cvsuser 05/02/20 02:28:14

Modified: examples/assembly getopt_demo.imc runtime/parrot/library/Getopt Long.imc t/library getopt_long.t Log:
Some beautification in the Getopt::Long PIR library.
Use the ".return ( ret )" syntax.
Revision Changes Path 1.8 +16 -20 parrot/examples/assembly/getopt_demo.imc Index: getopt_demo.imc ===================================================================
RCS file: /cvs/public/parrot/examples/assembly/getopt_demo.imc,v retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- getopt_demo.imc 28 Oct 2004 09:43:04 -0000 1.7
+++ getopt_demo.imc 20 Feb 2005 10:28:12 -0000 1.8
@@no-spam -1,5 +1,5 @@no-spam -# Copyright (C) 2001-2003 The Perl Foundation. All rights reserved.
-# $Id: getopt_demo.imc,v 1.7 2004/10/28 09:43:04 leo Exp $
+# Copyright (C) 2004-2005 The Perl Foundation. All rights reserved.
+# $Id: getopt_demo.imc,v 1.8 2005/02/20 10:28:12 bernhard Exp $
=head1 NAME @@no-spam -16,17 +16,20 @@no-spam This demo program shows how to handle command line arguments with the PIR library F<runtime/parrot/library/Getopt/Long.imc>.
-=head1 SUBROUTINES +=cut -=over 4
+# A dummy implementation of Getopt::Long +.include "library/Getopt/Long.imc"
-=item C<_main>
+=head1 SUBROUTINES +
+=head2 main This is executed when you call F<getopt_demo.imc>.
=cut -.sub _main +.sub main @no-spam .param pmc argv # Assemble specification for get_options @@no-spam -62,14 +65,14 @@no-spam # Was '--version' passed ?
is_defined = defined opt["version"]
unless is_defined goto NO_VERSION_FLAG - print "getopt_demo.imc version 0.02\n"
+ print "getopt_demo.imc 0.03\n"
end NO_VERSION_FLAG:
# Was '--help' passed ?
is_defined = defined opt["help"]
unless is_defined goto NO_HELP_FLAG - _usage( program_name )
+ usage( program_name )
end NO_HELP_FLAG:
@@no-spam -130,13 +133,9 @@no-spam CHECK_OTHER_ARG_LOOP:
if cnt_other_args < num_other_args goto REDO_OTHER_ARG_LOOP print "All args have been parsed.\n"
-
- # Do a lot of useful stuff here -
- end .end -=item C<_usage>
+=head2 usage Print the usage message.
@@no-spam -144,7 +143,7 @@no-spam =cut -.sub _usage prototyped +.sub usage .param string program_name print "Usage: ./parrot "
@@no-spam -163,15 +162,12 @@no-spam print " --bool a boolean option\n"
.end -# A dummy implementation of Getopt::Long -.include "library/Getopt/Long.imc"
-
-=back -
=head1 AUTHOR -Bernhard Schmalhofer <Bernhard.Schmalhofer@no-spam>
+Bernhard Schmalhofer - C<Bernhard.Schmalhofer@no-spam>
=head1 SEE ALSO F<runtime/parrot/library/Getopt/Long.imc>
+
+=cut 1.9 +14 -12 parrot/runtime/parrot/library/Getopt/Long.imc Index: Long.imc ===================================================================
RCS file: /cvs/public/parrot/runtime/parrot/library/Getopt/Long.imc,v retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Long.imc 2 Jan 2005 11:34:51 -0000 1.8
+++ Long.imc 20 Feb 2005 10:28:13 -0000 1.9
@@no-spam -1,4 +1,4 @@no-spam -# $Id: Long.imc,v 1.8 2005/01/02 11:34:51 leo Exp $
+# $Id: Long.imc,v 1.9 2005/02/20 10:28:13 bernhard Exp $
=head1 NAME @@no-spam -34,12 +34,15 @@no-spam .local string s s = opt["string"]
-
=head1 DESCRIPTION This PIR library can be used for parsing command line options.
A single subroutine, _get_options(), is provided.
+=cut +
+.include "library/dumper.imc"
+
=head1 SUBROUTINES =head2 _get_options @@no-spam -51,7 +54,7 @@no-spam =cut -.sub _get_options prototyped +.sub _get_options .param pmc argv .param pmc spec @@no-spam -166,18 +169,17 @@no-spam FINISH_PARSE_ARGV:
# Nothing to do here - .pcc_begin_return - .return opt - .pcc_end_return + .return ( opt )
.end -.include "library/dumper.imc"
-
=head1 TODO -Make it work for all cases, short options, long options and bundling -Recognise type of return value: string, integer, binary, array, hash -error reporting, more options +- Put the code into the namespace 'Getopt::Long'.
+- Remove need to clone argument vector +- Make it work for all cases, short options, long options and bundling.
+- Recognise type of return value: string, integer, binary, array, hash.
+- Get started on error reporting.
+- Provide more options =head1 AUTHOR @@no-spam -190,7 +192,7 @@no-spam =head1 COPYRIGHT -Copyright (C) 2003 The Perl Foundation. All rights reserved.
+Copyright (C) 2003-2005 The Perl Foundation. All rights reserved.
This program is free software. It is subject to the same license as The Parrot Interpreter.
1.3 +11 -11 parrot/t/library/getopt_long.t Index: getopt_long.t ===================================================================
RCS file: /cvs/public/parrot/t/library/getopt_long.t,v retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- getopt_long.t 22 Dec 2004 01:59:10 -0000 1.2
+++ getopt_long.t 20 Feb 2005 10:28:14 -0000 1.3
@@no-spam -1,5 +1,5 @@no-spam -# Copyright (C) 2001-2003 The Perl Foundation. All rights reserved.
-# $Id: getopt_long.t,v 1.2 2004/12/22 01:59:10 chromatic Exp $
+# Copyright (C) 2004-2005 The Perl Foundation. All rights reserved.
+# $Id: getopt_long.t,v 1.3 2005/02/20 10:28:14 bernhard Exp $
=head1 NAME @@no-spam -21,9 +21,12 @@no-spam use Parrot::Test tests => 1;
# no. 1
-output_is(<<'CODE', <<'OUT', "basic long options");
-##PIR##
-.sub _main +pir_output_is( <<'CODE', <<'OUT', "basic long options" );
+
+# A dummy implementation of Getopt::Long +.include "library/Getopt/Long.imc"
+
+.sub test @no-spam # Assemble specification for get_options # in an array of format specifiers @@no-spam -120,13 +123,8 @@no-spam CHECK_OTHER_ARG_LOOP:
if cnt_other_args < num_other_args goto REDO_OTHER_ARG_LOOP print "All args have been parsed.\n"
-
- end .end -# A dummy implementation of Getopt::Long -.include "library/Getopt/Long.imc"
-
CODE getopt_long.t 0.01
This is just a test.
@@no-spam -140,8 +138,10 @@no-spam =head1 AUTHOR -Bernhard Schmalhofer <Bernhard.Schmalhofer@no-spam>
+Bernhard Schmalhofer - C<Bernhard.Schmalhofer@no-spam>
=head1 SEE ALSO F<runtime/parrot/library/Getopt/Long.imc>
+
+=cut