The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
Changes 06
MANIFEST 03
META.json 22
META.yml 017
Makefile.PL 13
README 11
lib/Config/MVP/Assembler/WithBundles.pm 22
lib/Config/MVP/Assembler.pm 22
lib/Config/MVP/Reader/Findable.pm 22
lib/Config/MVP/Reader/Finder.pm 22
lib/Config/MVP/Reader/Hash.pm 075
lib/Config/MVP/Reader.pm 33
lib/Config/MVP/Section.pm 22
lib/Config/MVP/Sequence.pm 22
lib/Config/MVP.pm 22
t/hash.t 069
t/lib/Config/MVP/Reader/Test.pm 11
t/lib/Foo/Bar.pm 11
t/lib/Foo/Baz.pm 11
t/lib/Foo/Boo1.pm 11
t/lib/Foo/Boo2.pm 11
t/lib/Foo/Boondle.pm 11
t/lib/Foo/Metaboondle.pm 11
t/lib/Foo/Quux.pm 11
24 files changed (This is a version diff) 29201
@@ -1,5 +1,11 @@
 Revision history for Config-MVP
 
+0.093350  2009-12-01 06:58:48 America/New_York
+          added Config::MVP::Reader::Hash for use by adapter writers
+
+0.093330  2009-11-29 17:40:08 America/New_York
+          rebuild to include META.yml for sake of cpandeps scanner
+
 0.093120  2009-11-08
           add missing prereq
 
@@ -2,6 +2,7 @@ Changes
 LICENSE
 MANIFEST
 META.json
+META.yml
 Makefile.PL
 README
 dist.ini
@@ -11,10 +12,12 @@ lib/Config/MVP/Assembler/WithBundles.pm
 lib/Config/MVP/Reader.pm
 lib/Config/MVP/Reader/Findable.pm
 lib/Config/MVP/Reader/Finder.pm
+lib/Config/MVP/Reader/Hash.pm
 lib/Config/MVP/Section.pm
 lib/Config/MVP/Sequence.pm
 t/basic.t
 t/eg/config.mvp-test
+t/hash.t
 t/lib/Config/MVP/Reader/Test.pm
 t/lib/Foo/Bar.pm
 t/lib/Foo/Baz.pm
@@ -6,8 +6,8 @@
       "version" : 1.4,
       "url" : "http://module-build.sourceforge.net/META-spec-v1.4.html"
    },
-   "generated_by" : "Dist::Zilla version 1.092990",
-   "version" : "0.093120",
+   "generated_by" : "Dist::Zilla version 1.093290",
+   "version" : "0.093350",
    "name" : "Config-MVP",
    "author" : [
       "Ricardo Signes <rjbs@cpan.org>"
@@ -0,0 +1,17 @@
+---
+abstract: 'multivalue-property package-oriented configuration'
+author:
+  - 'Ricardo Signes <rjbs@cpan.org>'
+generated_by: 'Dist::Zilla version 1.093290'
+license: perl
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.4.html
+  version: 1.4
+name: Config-MVP
+requires:
+  Module::Pluggable::Object: 0
+  Moose: 0
+  Tie::IxHash: 0
+resources:
+  repository: http://github.com/rjbs/config-mvp
+version: 0.093350
@@ -2,6 +2,8 @@
 use strict;
 use warnings;
 
+
+
 use ExtUtils::MakeMaker;
 
 WriteMakefile(
@@ -9,7 +11,7 @@ WriteMakefile(
   NAME      => 'Config::MVP',
   AUTHOR    => "Ricardo\ Signes\ \<rjbs\@cpan\.org\>",
   ABSTRACT  => "multivalue\-property\ package\-oriented\ configuration",
-  VERSION   => '0.093120',
+  VERSION   => '0.093350',
   EXE_FILES => [ qw() ],
   (eval { ExtUtils::MakeMaker->VERSION(6.31) } ? (LICENSE => 'perl') : ()),
   PREREQ_PM    => {
@@ -1,7 +1,7 @@
 
 
 This archive contains the distribution Config-MVP, version
-0.093120:
+0.093350:
 
   multivalue-property package-oriented configuration
 
@@ -1,5 +1,5 @@
 package Config::MVP::Assembler::WithBundles;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 use Moose::Role;
@@ -77,7 +77,7 @@ Config::MVP::Assembler::WithBundles - a role to make assemblers expand bundles
 
 =head1 VERSION
 
-version 0.093120
+version 0.093350
 
 =head1 DESCRIPTION
 
@@ -1,5 +1,5 @@
 package Config::MVP::Assembler;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 use Moose;
@@ -112,7 +112,7 @@ Config::MVP::Assembler - multivalue-property config-loading state machine
 
 =head1 VERSION
 
-version 0.093120
+version 0.093350
 
 =head1 DESCRIPTION
 
@@ -1,5 +1,5 @@
 package Config::MVP::Reader::Findable;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 use Moose::Role;
@@ -53,7 +53,7 @@ Config::MVP::Reader::Findable - a config class that Config::MVP::Reader::Finder
 
 =head1 VERSION
 
-version 0.093120
+version 0.093350
 
 =head1 DESCRIPTION
 
@@ -1,5 +1,5 @@
 package Config::MVP::Reader::Finder;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 use Moose;
@@ -64,7 +64,7 @@ Config::MVP::Reader::Finder - a reader that finds an appropriate file
 
 =head1 VERSION
 
-version 0.093120
+version 0.093350
 
 =head1 DESCRIPTION
 
@@ -0,0 +1,75 @@
+package Config::MVP::Reader::Hash;
+our $VERSION = '0.093350';
+
+
+use Moose;
+with qw(Config::MVP::Reader);
+# ABSTRACT: a reader that tries to cope with a plain old hashref
+
+
+sub read_config {
+  my ($self, $arg) = @_;
+
+  confess "no hash given to $self" unless my $hash = $arg->{hash};
+
+  my $assembler = $self->assembler;
+
+  for my $name (keys %$hash) {
+    my $payload = { %{ $hash->{ $name } } };
+    my $package = delete($payload->{__package}) || $name;
+
+    $assembler->begin_section($package, $name);
+
+    for my $key (%$payload) {
+      my $val = $payload->{ $key };
+      my @values = ref $val ? @$val : $val;
+      $assembler->add_value($key => $_) for @values;
+    }
+
+    $assembler->end_section;
+  }
+
+  return $assembler->sequence;
+}
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
+1;
+
+__END__
+=pod
+
+=head1 NAME
+
+Config::MVP::Reader::Hash - a reader that tries to cope with a plain old hashref
+
+=head1 VERSION
+
+version 0.093350
+
+=head1 SYNOPSIS
+
+  my $sequence = Config::MVP::Reader::Hash->new->read_config({ hash => \%h });
+
+=head1 DESCRIPTION
+
+In some ways, this is the L<Config::MVP::Reader> of last resort.  Given a
+hashref, it attempts to interpret it as a Config::MVP::Sequence.  Because
+hashes are generally unordered, order can't be relied upon unless the hash tied
+to have order (presumably with L<Tie::IxHash>).  The hash keys are assumed to
+be section names and will be used as the section package moniker unless a
+L<__package> entry is found.
+
+=head1 AUTHOR
+
+  Ricardo Signes <rjbs@cpan.org>
+
+=head1 COPYRIGHT AND LICENSE
+
+This software is copyright (c) 2009 by Ricardo Signes.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut
+
@@ -1,5 +1,5 @@
 package Config::MVP::Reader;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 use Moose::Role;
@@ -33,7 +33,7 @@ Config::MVP::Reader - role to load MVP-style config from a file
 
 =head1 VERSION
 
-version 0.093120
+version 0.093350
 
 =head1 DESCRIPTION
 
@@ -67,7 +67,7 @@ of other classes or with pre-loaded sections.
 This method, B<which must be implemented by classes including this role>, is
 passed a hashref of arguments and returns a Config::MVP::Sequence.
 
-Valid arguments include:
+Likely arguments include:
 
   root     - the name of the directory in which to look
   filename - the filename in that directory to read
@@ -1,5 +1,5 @@
 package Config::MVP::Section;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 use Moose;
@@ -114,7 +114,7 @@ Config::MVP::Section - one section of an MVP configuration sequence
 
 =head1 VERSION
 
-version 0.093120
+version 0.093350
 
 =head1 DESCRIPTION
 
@@ -1,5 +1,5 @@
 package Config::MVP::Sequence;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 use Moose;
@@ -73,7 +73,7 @@ Config::MVP::Sequence - an ordered set of named configuration sections
 
 =head1 VERSION
 
-version 0.093120
+version 0.093350
 
 =head1 DESCRIPTION
 
@@ -1,5 +1,5 @@
 package Config::MVP;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 # ABSTRACT: multivalue-property package-oriented configuration
@@ -18,7 +18,7 @@ Config::MVP - multivalue-property package-oriented configuration
 
 =head1 VERSION
 
-version 0.093120
+version 0.093350
 
 =head1 SYNOPSIS
 
@@ -0,0 +1,69 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib 't/lib';
+
+{
+  package CMRFBA;
+  use Moose;
+  extends 'Config::MVP::Assembler';
+  with 'Config::MVP::Assembler::WithBundles';
+}
+
+{
+  package CMRFB;
+  use Moose;
+  extends 'Config::MVP::Reader::Hash';
+
+  sub build_assembler { CMRFBA->new; }
+}
+
+my $config = CMRFB->new->read_config({
+  hash => {
+    'Foo::Bar' => {
+      x => 1,
+      y => [ 2, 4 ],
+      z => 3,
+    },
+    'bz' => {
+      __package => 'Foo::Baz',
+      single => 1,
+      multi  => [ 2, 3 ],
+    },
+    'Foo::Metaboondle' => { },
+    'Foo::Quux' => {
+      a => 1,
+      b => 2,
+      c => 3,
+    }
+  },
+});
+
+my @sections = $config->sections;
+
+is(@sections, 6, "there are five sections");
+
+@sections = sort { lc $a->name cmp lc $b->name } @sections;
+my ($b_1, $b_2, $b_3, $baz, $bar, $quux) = @sections;
+
+is($bar->name,     'Foo::Bar',  '1st is Foo::Bar (name)');
+is($bar->package,  'Foo::Bar',  '1st is Foo::Bar (pkg)');
+
+is($baz->name,     'bz',        '2nd is bz (name)');
+is($baz->package,  'Foo::Baz',  '2nd is Foo::Baz (pkg)');
+
+is($b_1->name,     'boondle_1', '2nd is boondle_1 (name)');
+is($b_1->package,  'Foo::Boo1', '2nd is Foo::Boo1 (pkg)');
+
+is($b_2->name,     'boondle_2', '2nd is boondle_2 (name)');
+is($b_2->package,  'Foo::Boo2', '2nd is Foo::Boo2 (pkg)');
+
+is($b_3->name,     'boondle_3', '3rd is boondle_3 (name)');
+is($b_3->package,  'Foo::Boo2', '3rd is Foo::Boo2 (pkg)');
+
+is($quux->name,    'Foo::Quux', '4th is Foo::Quux (name)');
+is($quux->package, 'Foo::Quux', '4th is Foo::Quux (pkg)');
+
+done_testing;
@@ -1,5 +1,5 @@
 package Config::MVP::Reader::Test;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 use Moose;
@@ -1,5 +1,5 @@
 package Foo::Bar;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 sub mvp_multivalue_args { qw(y) }
@@ -1,5 +1,5 @@
 package Foo::Baz;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 sub mvp_multivalue_args { qw(multi) }
@@ -1,5 +1,5 @@
 package Foo::Boo1;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 1;
@@ -1,5 +1,5 @@
 package Foo::Boo2;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 1;
@@ -1,5 +1,5 @@
 package Foo::Boondle;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 
@@ -1,5 +1,5 @@
 package Foo::Metaboondle;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 
@@ -1,5 +1,5 @@
 package Foo::Quux;
-our $VERSION = '0.093120';
+our $VERSION = '0.093350';
 
 
 1;