[Bps-public-commit] Config-GitLike branch, master, updated. 1.12-6-g6580768

Alex Vandiver alexmv at bestpractical.com
Mon Mar 3 23:43:32 EST 2014


The branch, master has been updated
       via  6580768a7e2e35112981684d9bbed2abb2007404 (commit)
       via  35ddf29f247559b02d9603fe5b41969f223674a6 (commit)
       via  08b6d75098740bfb945f000043305d86fd521f33 (commit)
       via  41881e3e6aa471bb023356f72974e6455bb94843 (commit)
       via  5a108a8c41573d30faa2193ca80c2d29b534927a (commit)
       via  1f8d7b84af53bb0184d76da31051f7d2e8b6011a (commit)
      from  9b4034c46e810760749339fd4a0b5d71bafe77e5 (commit)

Summary of changes:
 Makefile.PL                    |   2 +-
 lib/Config/GitLike.pm          | 100 +++++++++++++++++++++++++++++++++++++----
 lib/Config/GitLike/Cascaded.pm |   7 +--
 3 files changed, 96 insertions(+), 13 deletions(-)

- Log -----------------------------------------------------------------
commit 1f8d7b84af53bb0184d76da31051f7d2e8b6011a
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Sep 16 12:43:28 2013 -0700

    Homedir expansion should only happen if ~ is the first character

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index 15de2fc..6dc10d5 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -171,7 +171,7 @@ sub load_file {
     }
 
     # Do some canonicalization
-    $filename =~ s/~/$ENV{'HOME'}/g;
+    $filename =~ s/^~/$ENV{'HOME'}/g;
     $filename = File::Spec->rel2abs($filename);
 
     return $self->data if grep {$_ eq $filename} @{$self->config_files};

commit 5a108a8c41573d30faa2193ca80c2d29b534927a
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Sep 16 12:46:28 2013 -0700

    Store the cleaned-up filename path, with ../s resolved
    
    Cwd::abs_path examines the filesystem to resolve /foo/../bar/ to /bar --
    while taking into account symlinks and other complicating factors.  Use
    it to store the simplest form of the filename loaded.
    
    As Cwd::abs_path returns undef if it cannot resolve the path, default
    back to the passed-in value, for error messages and the like.

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index 6dc10d5..8fe59d1 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -172,7 +172,8 @@ sub load_file {
 
     # Do some canonicalization
     $filename =~ s/^~/$ENV{'HOME'}/g;
-    $filename = File::Spec->rel2abs($filename);
+    $filename = Cwd::abs_path( File::Spec->rel2abs($filename, $args{relative}) )
+        || $filename;
 
     return $self->data if grep {$_ eq $filename} @{$self->config_files};
 

commit 41881e3e6aa471bb023356f72974e6455bb94843
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Sep 16 13:11:18 2013 -0700

    Nested configuration file inclusion, as git 1.7.10 and above implement

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index 8fe59d1..2a877a5 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -1,6 +1,6 @@
 package Config::GitLike;
 use Moo;
-use MooX::Types::MooseLike::Base qw(Bool HashRef ArrayRef Maybe Str);
+use MooX::Types::MooseLike::Base qw(Bool HashRef ArrayRef Maybe Str Int);
 
 use File::Spec;
 use Cwd;
@@ -70,6 +70,18 @@ has 'encoding' => (
     isa => Maybe[Str],
 );
 
+has 'include' => (
+    is => 'rw',
+    isa => Str,
+    default => sub { "include.path" },
+);
+
+has 'max_depth' => (
+    is => 'rw',
+    isa => Int,
+    default => sub { 10 },
+);
+
 sub set_multiple {
     my $self = shift;
     my ($name, $mult) = (@_, 1);
@@ -160,7 +172,6 @@ sub _read_config {
 
 sub load_file {
     my $ref = shift;
-    my ($filename) = @_;
 
     my $self;
     if (ref $ref) {
@@ -170,33 +181,72 @@ sub load_file {
         $self = $ref->new( confname => "" );
     }
 
+    unshift @_, "filename" if @_ % 2;
+    my %args = (
+        filename => undef,
+        silent   => 0,
+        relative => Cwd::cwd(),
+        depth    => 0,
+        force    => 0,
+        includes => 1,
+        @_,
+    );
+
+    my $filename = $args{filename};
+
     # Do some canonicalization
     $filename =~ s/^~/$ENV{'HOME'}/g;
     $filename = Cwd::abs_path( File::Spec->rel2abs($filename, $args{relative}) )
         || $filename;
 
-    return $self->data if grep {$_ eq $filename} @{$self->config_files};
+    return $self->data if grep {$_ eq $filename} @{$self->config_files}
+        and not $args{force};
 
     my $c = $self->_read_config($filename);
+    return $self->data if not $c and $args{silent};
     unless (defined $c) {
         die "Failed to load $filename: $!\n" if not ref $ref;
         return;
     }
 
+    # Note this filename as having been loaded
+    push @{$self->config_files}, $filename;
+
+    $self->set_multiple( $self->include ) if $self->include
+        and $args{includes};
+
     $self->data({}) unless $self->is_loaded;
     $self->parse_content(
         content  => $c,
         callback => sub {
+            my %def = @_;
             $self->define(@_, origin => $filename);
+
+            return unless $self->include and $args{includes};
+            my ($sec, $subsec, $name) = _split_key($self->include);
+            return unless lc( $def{section} || '') eq lc( $sec || '');
+            return unless ($def{subsection} || '') eq ($subsec || '');
+            return unless lc( $def{name} || '')    eq lc( $name || '');
+
+            die "Exceeded maximum include depth (".$self->max_depth.") ".
+                "while including $def{value} from $filename"
+                    if $args{depth} > $self->max_depth;
+
+            my (undef, $dir, undef) = File::Spec->splitpath($filename);
+
+            $self->load_file(
+                filename => $def{value},
+                silent   => 1,
+                relative => $dir,
+                depth    => $args{depth}+1,
+                force    => 1,
+            );
         },
         error    => sub {
             error_callback( @_, filename => $filename );
         },
     );
 
-    # note this filename as having been loaded
-    push @{$self->config_files}, $filename;
-
     return $self->data;
 }
 
@@ -1656,6 +1706,28 @@ This method can also be called as a class method, which will die if the
 file cannot be read.  If called as an instance method, returns undef on
 failure.
 
+This method may also be passed additional key-value parameters which
+control how the file is loaded:
+
+=over
+
+=item silent
+
+Defaults to off; if set, merely returns instead of die'ing if the file
+cannot be found or read.
+
+=item includes
+
+Defaults to on; if passed a false value, ignores the L</include>
+directive.
+
+=item force
+
+Defaults to off; if set, will re-load a file even if it was previously
+loaded.
+
+=back
+
 =head2 parse_content
 
 Parameters:
@@ -1705,6 +1777,15 @@ an exception with a useful message detailing the line number, position on
 the line, and contents of the bad line; if you find the need to use
 L<"parse_content"> elsewhere, you may find it useful as well.
 
+=head2 include ( $name )
+
+When reading configuration files, Git versions 1.7.10 and later parse
+the C<include.path> key as a directive to include an additional
+configuration file.  This option controls the equivalent behavior;
+setting it to a false value will disable inclusion, and any true value
+will be taken as the name of the configuration parameter which controls
+inclusion.  Defaults to C<include.path>, as Git does.
+
 =head2 set_multiple( $name )
 
 Mark the key string C<$name> as containing multiple values.

commit 08b6d75098740bfb945f000043305d86fd521f33
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Sep 16 13:11:36 2013 -0700

    Remove a non-ASCII character that snuck in

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index 2a877a5..4a2a04d 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -1805,7 +1805,7 @@ Parameters:
     name => 'str'
     value => 'str'
 
-Given a section, a key name, and a value¸ store this information
+Given a section, a key name, and a value, store this information
 in memory in the config object.
 
 Returns the value that was just defined on success, or undef

commit 35ddf29f247559b02d9603fe5b41969f223674a6
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Sep 16 13:11:45 2013 -0700

    Make dependency test happy

diff --git a/Makefile.PL b/Makefile.PL
index 4dcec4a..e021ab4 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -5,7 +5,7 @@ repository('http://github.com/bestpractical/config-gitlike');
 
 perl_version '5.008';
 requires 'Moo';
-requires 'MooX::Types::MooseLike';
+requires 'MooX::Types::MooseLike';  # MooX::Types::MooseLike::Base
 build_requires 'Test::Exception';
 extra_tests();
 sign();

commit 6580768a7e2e35112981684d9bbed2abb2007404
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Sep 16 13:13:04 2013 -0700

    Re-jigger POD to make the POD coverage test happy

diff --git a/lib/Config/GitLike/Cascaded.pm b/lib/Config/GitLike/Cascaded.pm
index b674961..7d0c7a7 100644
--- a/lib/Config/GitLike/Cascaded.pm
+++ b/lib/Config/GitLike/Cascaded.pm
@@ -26,10 +26,11 @@ Config::GitLike::Cascaded - git-like config file parsing with cascaded inheritan
 This module exists purely for backwards compatibility; its use is
 deprecated, and will be removed in a future release.
 
-=head1 DESCRIPTION
+=head1 METHODS
 
-This module simply defaults L<Config::GitLike/cascaded> to a true
-value.
+=head2 cascade
+
+This module simply defaults L<Config::GitLike/cascade> to a true value.
 
 =head1 SEE ALSO
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list