summaryrefslogtreecommitdiff
path: root/_posts/2009-06-22-modules-i-like-getopt-long-and-moosex-getopt.textile
diff options
context:
space:
mode:
authorFranck Cuny <franck.cuny@gmail.com>2013-11-26 10:36:10 -0800
committerFranck Cuny <franck.cuny@gmail.com>2013-11-26 10:36:10 -0800
commit8ddf2e94df70707b458528a437759b96046d3e01 (patch)
treed442818d92d3c9c6f7fcdc92857a1228963849a1 /_posts/2009-06-22-modules-i-like-getopt-long-and-moosex-getopt.textile
parentDon't need to use the IP in the makefile. (diff)
downloadlumberjaph-8ddf2e94df70707b458528a437759b96046d3e01.tar.gz
Huge update.
Moved all posts from textile to markdown. Updated all the CSS and styles. Added a new page for the resume.
Diffstat (limited to '')
-rw-r--r--_posts/2009-06-22-modules-i-like-getopt-long-and-moosex-getopt.md (renamed from _posts/2009-06-22-modules-i-like-getopt-long-and-moosex-getopt.textile)38
1 files changed, 17 insertions, 21 deletions
diff --git a/_posts/2009-06-22-modules-i-like-getopt-long-and-moosex-getopt.textile b/_posts/2009-06-22-modules-i-like-getopt-long-and-moosex-getopt.md
index 4f9470d..9decc0f 100644
--- a/_posts/2009-06-22-modules-i-like-getopt-long-and-moosex-getopt.textile
+++ b/_posts/2009-06-22-modules-i-like-getopt-long-and-moosex-getopt.md
@@ -1,12 +1,12 @@
---
layout: post
-category: perl
+summary: In which I talk about GetOpt::Long and Moosex::Getopt
title: Modules I like Getopt::Long and MooseX::Getopt
---
-h3. Getopt::Long
+## Getopt::Long
-"Getopt::long":http://search.cpan.org/perldoc?Getopt::Long is a useful module to parse command line arguements.
+[Getopt::long](http://search.cpan.org/perldoc?Getopt::Long) is a useful module to parse command line arguements.
A basic usage is something like this:
@@ -21,19 +21,19 @@ GetOptions('config=s' => \my $cfg_file,);
my $config = LoadFile $cfg_file
{% endhighlight %}
-In *GetOptions*, we require a value for config with *config=s*. If we wante an integer, we replace 's' with 'i', and for a floating point, with 'f'.
+In **GetOptions**, we require a value for config with **config=s**. If we wante an integer, we replace 's' with 'i', and for a floating point, with 'f'.
Call your script :
{% highlight bash %}
- script.pl --config=file.yml #this one works
- script.pl --config file.yml #this one too!
- script.pl -c file.yml #and this one too
+% script.pl --config=file.yml #this one works
+% script.pl --config file.yml #this one too!
+% script.pl -c file.yml #and this one too
{% endhighlight %}
The three syntaxes are understood.
-A good practices is to combine this module with "Pod::Usage":http://search.cpan.org/perldoc?Pod::Usage. Let's do some modifications on the example:
+A good practices is to combine this module with [Pod::Usage](http://search.cpan.org/perldoc?Pod::Usage). Let's do some modifications on the example:
{% highlight perl %}
#!/usr/bin/perl -w
@@ -72,7 +72,7 @@ Path to the config file
then
{% highlight bash %}
-$ perl uberscript
+% perl uberscript
Usage:
uberscript [options]
@@ -83,9 +83,9 @@ Usage:
From now if we call our script without argument, the POD will be printed on STDIN.
-h3. MooseX::Getopt
+## MooseX::Getopt
-"MooseX::Getopt":http://search.cpan.org/perldoc?MooseX::Getopt) is a Role that add a <code>new_with_options</code> to your object. We create a basic Object :
+[MooseX::Getopt](http://search.cpan.org/perldoc?MooseX::Getopt) is a Role that add a `new_with_options` to your object. We create a basic Object :
{% highlight perl %}
package OurShinyObject;
@@ -116,18 +116,14 @@ my $obj = OurShinyObject->new_from_options();
{% endhighlight %}
-bc. script.pl --config file.yml
+{% highlight sh%}
+% script.pl --config file.yml
+{% endhighlight %}
The role will set our attribute **context** using the value from the argument set on the command line.
-The
-
-{% highlight perl %}
-traits => ['NoGetopt']
-{% endhighlight %}
-
-indicate that this attributes will be not be read from the command line. An alternate way to do this is to prefix the attributes with *_*.
+The `traits => ['NoGetopt']` indicate that this attributes will be not be read from the command line. An alternate way to do this is to prefix the attributes with **_**.
-h3. conclusion (?)
+## conclusion (?)
-When you write a script, even if you're sure you will never need to have more than one argument, or that you never will have to update the code, *please* consider to use of *Getopt::Long* instead of a *shift @ARGV*, because we all know that you will at a certain point update this script and you will more than one argument :).
+When you write a script, even if you're sure you will never need to have more than one argument, or that you never will have to update the code, *please* consider to use of **Getopt::Long** instead of a `shift @ARGV`, because we all know that you will at a certain point update this script and you will more than one argument :).