[Bps-public-commit] Config-GitLike branch, master, updated. 129f847c7e129baf988966ce9f74f71fb6bdf305

Alex M Vandiver alexmv at bestpractical.com
Fri May 29 12:20:15 EDT 2009


The branch, master has been updated
       via  129f847c7e129baf988966ce9f74f71fb6bdf305 (commit)
       via  9164c6c22d8f52d6cf1b90d80beafabc3e07cc11 (commit)
       via  95048eac56f8c18931929cf13c05423098c3c996 (commit)
      from  8f1bb6176435a1b29fc93920b7c2d373fa752adc (commit)

Summary of changes:
 lib/Config/GitLike.pm |   68 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 53 insertions(+), 15 deletions(-)

- Log -----------------------------------------------------------------
commit 95048eac56f8c18931929cf13c05423098c3c996
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Fri May 29 12:10:55 2009 -0400

    Fix up a couple minor comment nits

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index bd2b647..eb69280 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -222,7 +222,7 @@ sub load_file {
     return $self->data;
 }
 
-=head2 parse_content( content = $str, callback = $sub, error = $sub )
+=head2 parse_content( content => $str, callback => $sub, error => $sub )
 
 Takes arguments consisting of C<content>, a string of the content of the
 configuration file to be parsed, C<callback>, a submethod to run on information
@@ -233,7 +233,7 @@ Returns undef on success and C<error($content)> on failure.
 
 C<callback> is called like:
 
-    callback(section => $str, offset => $num, length $num, name => $str, value => $str)
+    callback(section => $str, offset => $num, length => $num, name => $str, value => $str)
 
 C<name> and C<value> may be omitted if the callback is not being called on a
 key/value pair, or if it is being called on a key with no value.
@@ -260,8 +260,8 @@ sub parse_content {
         if ($c =~ s/\A[#;].*?$//im) {
             next;
         # [sub]section headers of the format [section "subsection"] (with
-        # unlimited whitespace between). any characters that appear
-        # after the closing square bracket are ignored.
+        # unlimited whitespace between). variable definitions may directly
+        # follow the section header, on the same line!
         } elsif ($c =~ s/\A\[([0-9a-z.-]+)(?:[\t ]*"(.*?)")?\]//im) {
             $section = lc $1;
             $section .= ".$2" if defined $2;
@@ -306,14 +306,14 @@ sub parse_content {
                 # escaped backspace in config is translated to actual backspace
                 } elsif ($c =~ s/\A\\b//im) {
                     $value .= "\b";
-                # valid value (possibly containing escape codes)
+                # quote-delimited value (possibly containing escape codes)
                 } elsif ($c =~ s/\A"([^"\\]*(?:(?:\\\n|\\[tbn"\\])[^"\\]*)*)"//im) {
                     my $v = $1;
                     # remove all continuations (\ followed by a newline)
                     $v =~ s/\\\n//g;
                     # swap escaped newlines with actual newlines
                     $v =~ s/\\n/\n/g;
-                    # swab escaped tabs with actual tabs
+                    # swap escaped tabs with actual tabs
                     $v =~ s/\\t/\t/g;
                     # swap escaped backspaces with actual backspaces
                     $v =~ s/\\b/\b/g;

commit 9164c6c22d8f52d6cf1b90d80beafabc3e07cc11
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Fri May 29 12:11:29 2009 -0400

    For paramhash functions, explicitly list parameters and defaults

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index eb69280..c7a90dc 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -246,7 +246,12 @@ C<error> is called like:
 
 sub parse_content {
     my $self = shift;
-    my %args = @_;
+    my %args = (
+        content  => "",
+        callback => sub {},
+        error    => sub {},
+        @_,
+    );
     my $c = $args{content};
     my $length = length $c;
 
@@ -347,7 +352,12 @@ sub parse_content {
 
 sub define {
     my $self = shift;
-    my %args = @_;
+    my %args = (
+        section => undef,
+        name    => undef,
+        value   => undef,
+        @_,
+    );
     return unless defined $args{name};
     $args{name} = lc $args{name};
     my $key = join(".", grep {defined} @args{qw/section name/});
@@ -360,7 +370,11 @@ sub define {
 
 sub cast {
     my $self = shift;
-    my %args = @_;
+    my %args = (
+        value => undef,
+        as    => undef, # bool, int, or num
+        @_,
+    );
     my $v = $args{value};
     return $v unless defined $args{as};
     if ($args{as} =~ /bool/i) {
@@ -390,7 +404,11 @@ loaded.
 
 sub get {
     my $self = shift;
-    my %args = @_;
+    my %args = (
+        key => undef,
+        as  => undef,
+        @_,
+    );
     $self->load unless $self->is_loaded;
     return undef unless exists $self->data->{$args{key}};
     my $v = $self->data->{$args{key}};
@@ -403,7 +421,11 @@ sub get {
 
 sub get_all {
     my $self = shift;
-    my %args = @_;
+    my %args = (
+        key => undef,
+        as  => undef,
+        @_,
+    );
     $self->load unless $self->is_loaded;
     return undef unless exists $self->data->{$args{key}};
     my $v = $self->data->{$args{key}};
@@ -436,7 +458,12 @@ sub format_section {
 
 sub format_definition {
     my $self = shift;
-    my %args = @_;
+    my %args = (
+        key   => undef,
+        value => undef,
+        bare  => undef
+        @_,
+    );
     my $quote = $args{value} =~ /(^\s|;|#|\s$)/ ? '"' : '';
     $args{value} =~ s/\\/\\\\/g;
     $args{value} =~ s/"/\\"/g;

commit 129f847c7e129baf988966ce9f74f71fb6bdf305
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Fri May 29 12:17:16 2009 -0400

    Make error callback get passed the original string and offset of error, not just remaining string

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index c7a90dc..b58cf93 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -240,7 +240,7 @@ key/value pair, or if it is being called on a key with no value.
 
 C<error> is called like:
 
-    error($content)
+    error( content => $content, offset => $offset )
 
 =cut
 
@@ -330,7 +330,13 @@ sub parse_content {
                     $value .= $1;
                 # unparseable
                 } else {
-                    return $args{error}->($c);
+                    # Note that $args{content} is the _original_
+                    # content, not the nibbled $c, which is the
+                    # remaining unparsed content
+                    return $args{error}->(
+                        content => $args{content},
+                        offset =>  $offset,
+                    );
                 }
             }
             $args{callback}->(
@@ -345,7 +351,12 @@ sub parse_content {
             last;
         # unparseable
         } else {
-            return $args{error}->($c);
+            # Note that $args{content} is the _original_ content, not
+            # the nibbled $c, which is the remaining unparsed content
+            return $args{error}->(
+                content => $args{content},
+                offset  => $offset,
+            );
         }
     }
 }

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



More information about the Bps-public-commit mailing list