package Config::Plugin::Tiny; use strict; use warnings; use Carp; use Config::Tiny; use vars qw(@EXPORT @ISA); @EXPORT = ('config_tiny'); @ISA = ('Exporter'); our $VERSION = '1.01'; # -------------------------------------------------- sub config_tiny { my($self, $file_name) = @_; $file_name ||= ''; my($config) = Config::Tiny -> read($file_name); croak 'Error: ' . Config::Tiny -> errstr . "\n" if (Config::Tiny -> errstr); return $config; } # End of config_tiny. # -------------------------------------------------- 1; =pod =head1 NAME Config::Plugin::Tiny - A plugin which uses Config::Tiny =head1 Synopsis package My::App; use strict; use warnings; use Config::Plugin::Tiny; # For config_tiny(). use File::Spec; # ------------------------------------------------ sub marine { my($self) = @_; my($config) = $self -> config_tiny(File::Spec -> catfile('some', 'dir', 'config.tiny.ini') ); } # End of marine. # -------------------------------------------------- 1; t/config.tiny.ini ships with the L distro, and is used in the test file t/test.t. =head1 Description When you 'use' this module (as in the Synopsis), it automatically imports into your class the method L to give you access to config data stored in an *.ini file. =head1 Distributions This module is available as a Unix-style distro (*.tgz). See L for help on unpacking and installing distros. =head1 Installation Install L as you would for any C module: Run: cpanm Config::Plugin::Tiny or run: sudo cpan Config::Plugin::Tiny or unpack the distro, and then either: perl Build.PL ./Build ./Build test sudo ./Build install or: perl Makefile.PL make (or dmake or nmake) make test make install =head1 Constructor and Initialization This module does not have, and does not need, a constructor. =head1 Methods =head2 config_tiny($file_name) Returns a *.ini-style config file as a hashref. Here, the [] indicate an optional parameter. The $file_name is passed to L's read($file_name) method. =head1 FAQ =head2 When would I use this module? In your sub-class of L for example, or anywhere else you want effortless access to a *.ini file. For example, if you wish to load a config for use by a module such as L, try Config::Plugin::Tiny or L. =head2 Why didn't you call the exported method config()? Because L allows both L and L to be used in the same code. =head2 Can this module be used in any non-CGI-Snapp module? Yes. =head2 Why don't you 'use Exporter;'? It is not needed; it would be for documentation only. For the record, Exporter V 5.567 ships with Perl 5.8.0. That's what I had in Build.PL and Makefile.PL until I tested the fact I can omit it. =head2 What's the error message format? Every message passed to croak matches /^Error/ and ends with "\n". =head1 See Also L The following are all part of this set of distros: L - A almost back-compat fork of CGI::Application L - A template-free demo of CGI::Snapp using just 1 run mode L - A template-free demo of CGI::Snapp using N run modes L - A template-free demo of CGI::Snapp using CGI::Snapp::Plugin::Forward L - A template-free demo of CGI::Snapp using Log::Handler::Plugin::DBI L - A wrapper around CGI::Snapp::Demo::Four, to simplify using Log::Handler::Plugin::DBI L - A plugin which uses Config::Tiny L - A plugin which uses Config::Tiny with 1 of N sections L - Persistent session data management L - A plugin for Log::Handler using Log::Hander::Output::DBI L - A helper for Log::Hander::Output::DBI to create your 'log' table =head1 Machine-Readable Change Log The file CHANGES was converted into Changelog.ini by L. =head1 Version Numbers Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions. =head1 Credits Please read L, since a lot of the ideas for this module were copied from L. =head1 Support Email the author, or log a bug on RT: L. =head1 Author L was written by Ron Savage Iron@savage.net.auE> in 2012. Home page: L. =head1 Copyright Australian copyright (c) 2012, Ron Savage. All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Artistic License, a copy of which is available at: http://www.opensource.org/licenses/index.html =cut