Config-YAML-1.42/0000755000175000017500000000000010315553060013327 5ustar mdximdxi00000000000000Config-YAML-1.42/t/0000755000175000017500000000000010315553060013572 5ustar mdximdxi00000000000000Config-YAML-1.42/t/01.init-read.t0000644000175000017500000000203210315552435016054 0ustar mdximdxi00000000000000use Test::More no_plan; use Config::YAML; my $c = Config::YAML->new(config => 't/test.yaml'); can_ok('Config::YAML','new'); isa_ok($c, 'Config::YAML'); ok($c->{_outfile} eq 't/test.yaml', "Implicit output declaration works"); ok($c->{clobber} == 1); ok($c->{silent} == 0, "Scalar input looks good."); ok($c->{media}[0] eq 'mp\d'); ok($c->{media}[5] eq 'wmv', "Array input looks good."); my $d = Config::YAML->new( config => 't/test.yaml', output => '~/.foorc', foo => 'bar', bar => 'foo', config => 1, output => 'quux', ); ok($d->{_outfile} eq '~/.foorc', "Explicit output declaration works"); ok($d->{foo} eq 'bar'); ok($d->{bar} eq 'foo', "User config variable declaration works"); ok($d->{config} == 1); ok($d->{output} eq 'quux', "Double declaration of config/output works"); $_ = 100; $c = Config::YAML->new( config => '/dev/null' ); ok($_ == 100, "Config::YAML now $_-safe");Config-YAML-1.42/t/00.load.t0000644000175000017500000000017010315450026015110 0ustar mdximdxi00000000000000use Test::More tests => 1; BEGIN { use_ok( 'Config::YAML' ); } diag( "Testing Config::YAML $Config::YAML::VERSION" ); Config-YAML-1.42/t/06.write.t0000644000175000017500000000050410315450026015332 0ustar mdximdxi00000000000000use Test::More tests => 1; use Config::YAML; my $c = Config::YAML->new( config => 't/test.yaml', output => 't/test.out' ); $c->write; my $d = Config::YAML->new( config => 't/test.out'); ok($c->{media}[4] eq $d->{media}[4], "YAML output is working"); unlink 't/test.out';Config-YAML-1.42/t/test.yaml0000644000175000017500000000032310315450026015431 0ustar mdximdxi00000000000000--- #YAML:1.0 clean: 0 clobber: 1 debug: 0 dotfiles: 0 media: - mp\d - ogg - mpe?g - mov - avi - wmv - asf - qt - gif - jpe?g - png monly: 0 nodirs: 0 nolog: 0 silent: 0 undo: 0 verbose: 0 Config-YAML-1.42/t/test2.yaml0000644000175000017500000000007110315450026015513 0ustar mdximdxi00000000000000--- #YAML:1.0 nuval: 1 clobber: 2 media: - ogg - mp3 Config-YAML-1.42/t/pod.t0000644000175000017500000000021410315450026014534 0ustar mdximdxi00000000000000#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Config-YAML-1.42/t/05.fold.t0000644000175000017500000000036410315450026015127 0ustar mdximdxi00000000000000use Test::More tests => 2; use Config::YAML; @config{"attrib1", "attrib2"} = qw(37 foo); my $c = Config::YAML->new(config => 't/test.yaml'); $c->fold(\%config); ok($c->{attrib1} == 37); ok($c->{attrib2} eq 'foo', "Folding from hash works."); Config-YAML-1.42/t/03.getopt-integrate.t0000644000175000017500000000051210315450026017456 0ustar mdximdxi00000000000000use Test::More no_plan; use Config::YAML; use Getopt::Long; @ARGV = qw( --noclobber ); my $c = Config::YAML->new(config => 't/test.yaml'); ok($c->{clobber} == 1, "This should always work if the previous tests did"); GetOptions( $c, 'clobber|c!' ); ok($c->{clobber} == 0, "Param update via Getopt worked"); Config-YAML-1.42/t/04.get-set.t0000644000175000017500000000123710315450026015552 0ustar mdximdxi00000000000000use Test::More tests => 7; use Config::YAML; my $c = Config::YAML->new(config => 't/test.yaml'); is($c->{clobber}, 1, "This should always work if the previous tests did"); is($c->get_clobber, 1, "OO value retreival works"); $c->set_clobber(5); is($c->get_clobber, 5, "OO value specification works"); my $media = $c->get_media; is($media->[1], 'ogg', "get_ting data structures works"); my @newmedia = qw(oil stucco acrylics latex); $c->set_media(\@newmedia); is($c->{media}[1], 'stucco', "set_ting data structures works"); $c->set_fnord(42); is($c->get_fnord, 42, "creating new attribs works"); is($c->get_splort, undef, "getting nonexistent attribs returns undef");Config-YAML-1.42/t/02.read-overlay.t0000644000175000017500000000071310315450026016570 0ustar mdximdxi00000000000000use Test::More no_plan; use Config::YAML; my $c = Config::YAML->new(config => 't/test.yaml'); ok($c->{clobber} == 1, "This should always work if the previous tests did"); $c->read('t/test2.yaml'); ok($c->{clobber} == 2, "Reassignment from secondary conf ok"); ok($c->{nuval} == 1, "Assignment from secondary conf ok"); ok($c->{media}[0] eq 'ogg'); ok($c->{media}[1] eq 'mp3'); ok(!(defined $c->{media}[2]), "Array (re)assignment from secondary conf ok"); Config-YAML-1.42/t/pod-coverage.t0000644000175000017500000000025410315450026016331 0ustar mdximdxi00000000000000#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); Config-YAML-1.42/lib/0000755000175000017500000000000010315553060014075 5ustar mdximdxi00000000000000Config-YAML-1.42/lib/Config/0000755000175000017500000000000010315553060015302 5ustar mdximdxi00000000000000Config-YAML-1.42/lib/Config/YAML.pm0000644000175000017500000001575710315552463016427 0ustar mdximdxi00000000000000package Config::YAML; # $Id: YAML.pm 41 2005-03-15 22:33:09Z mdxi $ use warnings; use strict; use YAML; use vars qw( $AUTOLOAD ); =head1 NAME Config::YAML - Simple configuration automation =head1 VERSION Version 1.42 =cut our $VERSION = '1.42'; =head1 SYNOPSIS Config::YAML is a somewhat object-oriented wrapper around the YAML module which makes reading and writing configuration files simple. Handling multiple config files (e.g. system and per-user configuration, or a gallery app with per-directory configuration) is a snap. use Config::YAML; # create Config::YAML object with any desired initial options # parameters; load system config; set alternate output file my $c = Config::YAML->new( config => "/usr/share/foo/globalconf", output => "~/.foorc", param1 => value1, param2 => value2, ... paramN => valueN, ); # integrate user's own config $c->read("~/.foorc"); # integrate command line args using Getopt::Long $rc = GetOptions ( $c, 'param1|p!', 'param2|P', 'paramN|n', ); # Write configuration state to disk $c->write; # simply get params back for use... do_something() unless $c->{param1}; # or get them more OO-ly if that makes you feel better my $value = $c->get_param2; =cut =head1 METHODS =head2 new Creates a new Config::YAML object. my $c = Config::YAML->new( config => initial_config, output => output_config ); The C parameter specifies the file to be read in during object creation. It is required, and must be the first parameter given. If the second parameter is C, then it is used to specify the file to which configuration data will later be written out. This positional dependancy makes it possible to have parameters named "config" and/or "output" in config files. Initial configuration values can be passed as subsequent parameters to the constructor: my $c = Config::YAML->new( config => "~/.foorc", foo => "abc", bar => "xyz", baz => [ 1, 2, 3 ], ); =cut sub new { my $class = shift; my %priv = (); my %args = (); die("Can't create Config::YAML object with no config file.\n") if ($_[0] ne "config"); shift; $priv{config} = shift; if (@_ && ($_[0] eq "output")) { shift; $priv{output} = shift; } if (@_ && ($_[0] eq "strict")) { shift; $priv{strict} = shift; } my $self = bless { _infile => $priv{config}, _outfile => $priv{output} || $priv{config}, _strict => $priv{strict} || 0, }, $class; %args = @_; @{$self}{keys %args} = values %args; $self->read; return $self; } =head2 get_*/set_* If you'd prefer not to directly molest the object to store and retrieve configuration data, autoloading methods of the forms C and C are provided. Continuing from the previous example: print $c->get_foo; # prints "abc" my $val = $c->get_quux; # $c->{quux} doesn't exist; returns undef $c->set_bar(30); # $c->{bar} now equals 30, not "xyz" my @list = qw(alpha beta gamma); $c->set_baz(\@list); # $c->{baz} now a reference to @list =cut sub Config::YAML::AUTOLOAD { no strict 'refs'; my ($self, $newval) = @_; if ($AUTOLOAD =~ /.*::get_(\w+)/) { my $attr = $1; return undef if (!defined $self->{$attr}); *{$AUTOLOAD} = sub { return $_[0]->{$attr} }; return $self->{$attr}; } if ($AUTOLOAD =~ /.*::set_(\w+)/) { my $attr = $1; *{$AUTOLOAD} = sub { $_[0]->{$attr} = $_[1]; return }; $self->{$attr} = $newval; return; } } =head2 fold Convenience method for folding multiple values into the config object at once. Requires a hashref as its argument. $prefs{theme} = param(theme); $prefs{format} = param(format); $prefs{sortby} = param(order); $c->fold(\%prefs); my $format = $c->get_format; # value matches that of param(format) =cut sub fold { my ($self, $data) = @_; # add check for HASHREF when strict mode is implemented @{$self}{keys %{$data}} = values %{$data}; } =head2 read Imports a YAML-formatted config file. $c->read('/usr/share/fooapp/fooconf'); C is called at object creation and imports the file specified by C<< new(config=>) >>, so there is no need to call it manually unless multiple config files exist. =cut sub read { my ($self, $file) = @_; $self->{_infile} = $file if $file; my $yaml; my $line; open(FH,'<',$self->{_infile}) or die "Can't open $self->{_infile}; $!\n"; while ($line = ) { next if ($line =~ /^\-{3,}/); next if ($line =~ /^#/); next if ($line =~ /^$/); $yaml .= $line; } close(FH); my $tmpyaml = Load($yaml); @{$self}{keys %{$tmpyaml}} = values %{$tmpyaml}; # woo, hash slice } =head2 write Dump current configuration state to a YAML-formatted flat file. $c->write; The file to be written is specified in the constructor call. See the C method documentation for details. =cut sub write { my $self = shift; my %tmpyaml; # strip out internal state parameters while(my($k,$v) = each%{$self}) { $tmpyaml{$k} = $v unless ($k =~ /^_/); } # write data out to file open(FH,'>',$self->{_outfile}) or die "Can't open $self->{_outfile}: $!\n"; print FH Dump(\%tmpyaml); close(FH); } =head1 DEPRECATED METHODS These methods have been superceded and will likely be removed in the next release. =head2 get Returns the value of a parameter. print $c->get('foo'); =cut sub get { my ($self, $arg) = @_; return $self->{$arg}; } =head2 set Sets the value of a parameter: $c->set('foo',1); my @paints = qw( oil acrylic tempera ); $c->set('paints', \@paints); =cut sub set { my ($self, $key, $val) = @_; $self->{$key} = $val; } =head1 AUTHOR Shawn Boyette (C<< >>) Original implementation by Kirrily "Skud" Robert (as C). =head1 BUGS =over =item Config::YAML ignores the YAML document separation string (C<--->) because it has no concept of multiple targets for the data coming from a config file. =back Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 COPYRIGHT & LICENSE Copyright 2004 Shawn Boyette, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of Config::YAML Config-YAML-1.42/MANIFEST0000644000175000017500000000040410315450026014454 0ustar mdximdxi00000000000000Changes MANIFEST META.yml # Will be created by "make dist" Makefile.PL README lib/Config/YAML.pm t/00.load.t t/01.init-read.t t/02.read-overlay.t t/03.getopt-integrate.t t/04.get-set.t t/05.fold.t t/06.write.t t/test.yaml t/test2.yaml t/pod-coverage.t t/pod.t Config-YAML-1.42/META.yml0000644000175000017500000000057710315450026014607 0ustar mdximdxi00000000000000# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Config-YAML version: 1.41 version_from: lib/Config/YAML.pm installdirs: site requires: Test::More: 0 YAML: 0.35 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 Config-YAML-1.42/Makefile.PL0000644000175000017500000000100210315450026015270 0ustar mdximdxi00000000000000use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Config::YAML', AUTHOR => 'Shawn Boyette ', VERSION_FROM => 'lib/Config/YAML.pm', ABSTRACT_FROM => 'lib/Config/YAML.pm', PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, 'YAML' => 0.35, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Config-YAML-*' }, ); Config-YAML-1.42/Changes0000644000175000017500000000261110315450701014620 0ustar mdximdxi00000000000000Revision history for Config-YAML 1.42 2005-09-26 * rt.cpan ticket #14625: Config::YAML appears not to be $_ safe Fixes for this bug report 1.41 2005-03-16 * Bug from 1.40 also occurred in fold(). Fixed. 1.40 2005-03-15 * Fixed bug in hash slice operation in new() and read() methods. RT#11886. Thanks to JFITZ for finding it and mugwump for pointing out the syntax error. 1.37 2005-01-16 2245EDT * get() and set() methods deprecated in favor of autoloading accessor functions /a la/ The Damian. * Doc tweaks 1.28 2004-11-14 2053EDT * POD typos fixed, minor doc tweaks 1.27 2004-11-13 1235EDT * YAML.pl now listed as a dependancy (dur). * More/better tests for get() and set() methods. * Documentation improvements. 1.22 2004-10-03 1945EST * In new(), the 'config' and 'output' parameters must now be the first and (still optionally) second parameters passed. This is so that they can be repeated, allowing the user to set their own non-special 'config' and 'output' parameters in the actual configuration hash. * Doc tweaks to reflect this as well as more general tweaks. 1.21 2004-10-02 1448EST * Doc cleanups 1.00 2004-10-01 1550EST * First version, released on an unsuspecting world. Config-YAML-1.42/README0000644000175000017500000000111710315450026014205 0ustar mdximdxi00000000000000Config-YAML This is a wrapper around the YAML module to enable simple reading and writing of YAML-formatted configuration files. It supports multiple input files and integration with Getopt::Long to handle all your configuration needs. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install COPYRIGHT AND LICENCE Put the correct copyright and licence information here. Copyright (C) 2004 Shawn Boyette This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.