Permalink
Browse files

pod updated

  • Loading branch information...
1 parent 9c3a222 commit 557bbebd83c38b5d94ea1deebc5c8590c3855a3a @kawanet committed Apr 24, 2012
Showing with 194 additions and 13 deletions.
  1. +1 −1 .gitignore
  2. +9 −1 Makefile.PL
  3. +103 −0 README
  4. +37 −11 lib/Config/Pico.pm
  5. +44 −0 make-dist.sh
View
@@ -26,7 +26,7 @@ Build.bat
Makefile
Makefile.old
MANIFEST.bak
-META.yml
+# META.yml
MYMETA.yml
nytprof.out
pm_to_blib
View
@@ -3,10 +3,18 @@ use ExtUtils::MakeMaker;
my $opt = {
NAME => 'Config::Pico',
VERSION_FROM => 'lib/Config/Pico.pm',
+ CONFIGURE_REQUIRES => {
+ 'ExtUtils::MakeMaker' => '6.55',
+ },
+ BUILD_REQUIRES => {
+ 'Test::More' => '0',
+ },
PREREQ_PM => {
- 'Test::More' => '0',
+ # no dependencies
},
LICENSE => 'perl',
+ ABSTRACT_FROM => 'lib/Config/Pico.pm',
+ AUTHOR => 'Yusuke Kawasaki',
};
WriteMakefile( %$opt );
View
103 README
@@ -0,0 +1,103 @@
+NAME
+ Config::Pico - Perl Interpretative COnfiguration: do "config.pl"
+
+SYNOPSIS
+ use Config::Pico;
+
+ # general use
+ @config = pico($basedir, "config.pl");
+
+ # user agent
+ $ua = LWP::UserAgent->new(pico "lwp.pl");
+
+ # logger
+ $logger = Log::Dispatch->new(pico "log.pl");
+
+ # database
+ $dbh = DBI->connect(pico "dbi.pl");
+
+ lwp.pl configuration for LWP::UserAgent
+
+ +(
+ agent => "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
+ max_redirect => 5,
+ timeout => 30,
+ env_proxy => 1,
+ );
+
+ log.pl configuration for Log::Dispatch
+
+ +(outputs => [
+ ['File', min_level => 'debug', filename => 'logfile'],
+ ['Screen', min_level => 'warning'],
+ ]);
+
+ dbi.pl configuration for DBI, DBD::SQLite
+
+ +(
+ "dbi:SQLite:dbname=dbfile", "", "", {
+ AutoCommit => 1,
+ RaiseError => 1,
+ sqlite_unicode => 1,
+ sqlite_allow_multiple_statements => 1,
+ },
+ );
+
+ another configuration for DBD::MySQL
+
+ local %_ = (
+ driver => 'mysql',
+ database => 'xxxx',
+ host => 'localhost',
+ port => '3306',
+ username => 'xxxxxx',
+ password => 'xxxxxxxx',
+ attr => {
+ AutoCommit => 1,
+ RaiseError => 1,
+ mysql_enable_utf8 => 1,
+ },
+ );
+
+ +("dbi:$_{driver}:database=$_{database};host=$_{host};port=$_{port}", $_{username}, $_{password}, $_{attr});
+
+DESCRIPTION
+ Use Perl as a DSL to configure you app. This module exports "pico()"
+ function which loads a configuration file written in Perl syntax. You
+ don't have to learn other languages/notations like YAML, XML, JSON, etc.
+ as you already know Perl.
+
+FUNCTION
+ pico([$dir,] $file)
+ The first argument $dir is optional and specify a base path. This would
+ help you when you have variations in environments which need a set of
+ configuration files, respectively.
+
+ my $conf = pico("config/$ENV{PLACK_ENV}", "dbi.pl");
+
+ The last argument $file is a filename which is wrtten in Perl to load.
+
+ my $conf = pico $file;
+
+ is equivalent to
+
+ my $conf = do $file;
+
+ Another difference between those two is that, in case of $file is not
+ exist, "pico()" raises an error while "do()" doesn't. It'd be still easy
+ for you to switch off the module and call "do()" instead of "pico()".
+
+SYNTAX CHECK
+AUTHOR
+ Yusuke Kawasaki http://www.kawa.net/
+
+COPYRIGHT
+ The following copyright notice applies to all the files provided in this
+ distribution, including binary files, unless explicitly noted otherwise.
+
+ Copyright 2012 Yusuke Kawasaki
+
+LICENSE
+ This library is free software; you can redistribute it and/or modify it
+ under the same terms as Perl itself.
+
View
@@ -25,9 +25,6 @@ sub pico {
wantarray ? @conf : pop @conf;
}
-;1;
-__END__
-
1;
__END__
@@ -37,7 +34,7 @@ __END__
=head1 NAME
-Config::Pico - Picoscale Perl Interpretative COnfiguration
+Config::Pico - Perl Interpretative COnfiguration: do "config.pl"
=head1 SYNOPSIS
@@ -47,13 +44,13 @@ Config::Pico - Picoscale Perl Interpretative COnfiguration
@config = pico($basedir, "config.pl");
# user agent
- $ua = LWP::UserAgent->new(pico("lwp.pl"));
+ $ua = LWP::UserAgent->new(pico "lwp.pl");
# logger
- $logger = Log::Dispatch->new(pico("log.pl"));
+ $logger = Log::Dispatch->new(pico "log.pl");
# database
- $dbh = DBI->connect(pico("dbi.pl"));
+ $dbh = DBI->connect(pico "dbi.pl");
lwp.pl configuration for L<LWP::UserAgent>
@@ -75,9 +72,10 @@ dbi.pl configuration for L<DBI>, L<DBD::SQLite>
+(
"dbi:SQLite:dbname=dbfile", "", "", {
+ AutoCommit => 1,
+ RaiseError => 1,
sqlite_unicode => 1,
sqlite_allow_multiple_statements => 1,
- sqlite_use_immediate_transaction => 1,
},
);
@@ -88,11 +86,11 @@ another configuration for L<DBD::MySQL>
database => 'xxxx',
host => 'localhost',
port => '3306',
- username => 'xxxx',
+ username => 'xxxxxx',
password => 'xxxxxxxx',
attr => {
- RaiseError => 1,
AutoCommit => 1,
+ RaiseError => 1,
mysql_enable_utf8 => 1,
},
);
@@ -101,7 +99,35 @@ another configuration for L<DBD::MySQL>
=head1 DESCRIPTION
-TBD
+Use Perl as a DSL to configure you app. This module exports C<pico()>
+function which loads a configuration file written in Perl syntax.
+You don't have to learn other languages/notations like YAML, XML,
+JSON, etc. as you already know Perl.
+
+=head1 FUNCTION
+
+=head2 pico([$dir,] $file)
+
+The first argument C<$dir> is optional and specify a base path.
+This would help you when you have variations in environments
+which need a set of configuration files, respectively.
+
+ my $conf = pico("config/$ENV{PLACK_ENV}", "dbi.pl");
+
+The last argument C<$file> is a filename which is wrtten in Perl to load.
+
+ my $conf = pico $file;
+
+is equivalent to
+
+ my $conf = do $file;
+
+Another difference between those two is that, in case of C<$file>
+is not exist, C<pico()> raises an error while C<do()> doesn't.
+It'd be still easy for you to switch off the module and call C<do()>
+instead of C<pico()>.
+
+=head1 SYNTAX CHECK
=head1 AUTHOR
View
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+die () {
+ echo "$*" >&2
+ exit 1
+}
+doit () {
+ echo "\$ $*" >&2
+ $* || die "[ERROR:$?]"
+}
+
+[ -f Makefile ] && doit make clean
+[ -f Makefile.old ] && doit /bin/rm -f Makefile.old
+[ -f META.yml ] || doit touch META.yml
+
+egrep -v '^(lib/.*\.pm|t/.*\.t)$' MANIFEST > MANIFEST~
+ls Makefile.PL README Changes MANIFEST META.yml COPYING >> MANIFEST~ 2> /dev/null
+find lib -type f -name '*.pm' >> MANIFEST~
+ls t/*.t >> MANIFEST~
+LC_ALL=C sort MANIFEST~ | uniq > MANIFEST~~
+/bin/mv -f MANIFEST~~ MANIFEST~
+diff MANIFEST MANIFEST~ > /dev/null || doit /bin/mv -f MANIFEST~ MANIFEST
+/bin/rm -f MANIFEST~
+
+doit perl Makefile.PL
+doit make metafile
+newmeta=`ls -t */META.yml | head -1`
+diff META.yml $newmeta > /dev/null || doit /bin/cp -f $newmeta META.yml
+
+doit make disttest
+
+name=`grep '^name:' META.yml | sed 's#^.*: *##; s#-#/#g;'`
+main=`grep "$name.pm$" < MANIFEST | head -1`
+[ "$main" == "" ] && die "main module is not found in MANIFEST"
+doit pod2text $main > README~
+diff README README~ > /dev/null || doit /bin/mv -f README~ README
+/bin/rm -f README~
+
+doit make dist
+[ -d blib ] && doit /bin/rm -fr blib
+[ -f pm_to_blib ] && doit /bin/rm -f pm_to_blib
+[ -f Makefile.old ] && doit /bin/rm -f Makefile.old
+
+ls -lt *.tar.gz | head -1

0 comments on commit 557bbeb

Please sign in to comment.