[Bps-public-commit] Config-GitLike branch, master, updated. cbcda5c26969ee695b904b8aecacc4ff4c232070
spang at bestpractical.com
spang at bestpractical.com
Wed Jun 3 14:58:51 EDT 2009
The branch, master has been updated
via cbcda5c26969ee695b904b8aecacc4ff4c232070 (commit)
via 7a2162540b2bdb620b3ba3b3cceb1c80608c8d72 (commit)
via c631e2708ce6c8ee0abb03ddf72ed92aabb57dd4 (commit)
via 0f3a6f4aaddd5ea346defe282573ee3368b3f201 (commit)
via 6626d72211d987e221912949074f8080e674266e (commit)
via 3edfddddeb9978f5541922b8e04ada39ae6932e9 (commit)
from 902073d4cea14df3ba4936a3de69dc2e9b8ebd41 (commit)
Summary of changes:
.gitignore | 1 +
lib/Config/GitLike.pm | 64 +++++++++++++++++++++++++++++++-----------------
t/t1300-repo-config.t | 17 ++++--------
3 files changed, 48 insertions(+), 34 deletions(-)
create mode 100644 .gitignore
- Log -----------------------------------------------------------------
commit 3edfddddeb9978f5541922b8e04ada39ae6932e9
Author: Christine Spang <spang at mit.edu>
Date: Wed Jun 3 21:23:16 2009 +0300
parser fix: don't tack trailing whitespace onto values, even if the value is followed by a comment
diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index 33b35b4..8237c4f 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -257,11 +257,11 @@ sub parse_content {
my($section, $prev) = (undef, '');
while (1) {
- # drop leading blank lines
+ # drop leading white space and blank lines
$c =~ s/\A\s*//im;
my $offset = $length - length($c);
- # drop lines that start with a comment
+ # drop to end of line on comments
if ($c =~ s/\A[#;].*?$//im) {
next;
# [sub]section headers of the format [section "subsection"] (with
@@ -289,16 +289,17 @@ sub parse_content {
} elsif ($c =~ s/\A([0-9a-z-]+)[\t ]*=[\t ]*//im) {
my $name = $1;
my $value = "";
+ # parse the value
while (1) {
- # concatenate whitespace
- if ($c =~ s/\A[\t ]+//im) {
+ # comment or no content left on line
+ if ($c =~ s/\A([ \t]*[#;].*?)?$//im) {
+ last;
+ # any amount of whitespace between words becomes a single space
+ } elsif ($c =~ s/\A[\t ]+//im) {
$value .= ' ';
- # line continuation (\ character proceeded by new line)
+ # line continuation (\ character followed by new line)
} elsif ($c =~ s/\A\\\r?\n//im) {
next;
- # comment
- } elsif ($c =~ s/\A([#;].*?)?$//im) {
- last;
# escaped quote characters are part of the value
} elsif ($c =~ s/\A\\(['"])//im) {
$value .= $1;
commit 6626d72211d987e221912949074f8080e674266e
Author: Christine Spang <spang at mit.edu>
Date: Wed Jun 3 21:27:44 2009 +0300
make dump return a string rather than printing. this is more useful for things like tests.
diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index 8237c4f..ba35fe1 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -493,24 +493,27 @@ sub get_all {
=head2 dump
-Print all configuration data, sorted in ASCII order, in the form:
+Return a string containing all configuration data, sorted in ASCII order, in
+the form:
section.key=value
section2.key=value
-This is similar to the output of C<git config --list>.
+If you print this string, it is similar to the output of C<git config --list>.
=cut
sub dump {
my $self = shift;
+ my $data = '';
for my $key (sort keys %{$self->data}) {
if (defined $self->data->{$key}) {
- print "$key=".$self->data->{$key}."\n";
+ $data .= "$key=".$self->data->{$key}."\n";
} else {
- print "$key\n";
+ $data .= "$key\n";
}
}
+ return $data;
}
=head2 format_section 'section.subsection'
commit 0f3a6f4aaddd5ea346defe282573ee3368b3f201
Author: Christine Spang <spang at mit.edu>
Date: Wed Jun 3 21:30:05 2009 +0300
un-TODO testing dump. since our interface doesn't keep track of key/value data, make the tests expect the output to be sorted
diff --git a/t/t1300-repo-config.t b/t/t1300-repo-config.t
index d810f31..8fde70c 100644
--- a/t/t1300-repo-config.t
+++ b/t/t1300-repo-config.t
@@ -355,21 +355,16 @@ EOF
is(slurp($config_filename), $expect, 'hierarchical section value');
-# TODO git outputs keys in the order they are in the config file;
-# this won't exactly match since ->dump outputs sorted
-TODO: {
- local $TODO = 'git config doesn\'t sort when using --list';
-
- $expect = <<'EOF'
+$expect = <<'EOF'
+123456.a123=987
beta.noindent=sillyValue
nextsection.nonewline=wow2 for me
-123456.a123=987
version.1.2.3eX.alpha=beta
EOF
- ;
+;
- is($config->dump, $expect, 'working dump');
-}
+$config->load;
+is($config->dump, $expect, 'working dump');
TODO: {
local $TODO = 'get_regexp is not implemented';
commit c631e2708ce6c8ee0abb03ddf72ed92aabb57dd4
Author: Christine Spang <spang at mit.edu>
Date: Wed Jun 3 21:51:42 2009 +0300
kill an unnecessary \
diff --git a/t/t1300-repo-config.t b/t/t1300-repo-config.t
index 8fde70c..6f03c7a 100644
--- a/t/t1300-repo-config.t
+++ b/t/t1300-repo-config.t
@@ -481,7 +481,7 @@ EOF
is(slurp($config_filename), $expect, 'rename succeeded');
throws_ok { $config->rename_section( from => 'branch."world domination"', to =>
- 'branch.drei', filename => $config_filename ) } \
+ 'branch.drei', filename => $config_filename ) }
qr/rename non-existing section/, 'rename non-existing section';
is(slurp($config_filename), $expect,
commit 7a2162540b2bdb620b3ba3b3cceb1c80608c8d72
Author: Christine Spang <spang at mit.edu>
Date: Wed Jun 3 21:52:40 2009 +0300
add .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..259feb8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+pm_to_blib
commit cbcda5c26969ee695b904b8aecacc4ff4c232070
Author: Christine Spang <spang at mit.edu>
Date: Wed Jun 3 21:58:05 2009 +0300
pod updates
diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index ba35fe1..aef60bf 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -36,12 +36,17 @@ Config::GitLike - git-compatible config file parsing
=head1 SYNOPSIS
+ use Config::GitLike;
+
+ my $c = Config::GitLike->new(confname => 'config');
+ $c->load;
+
+ $c->get(
+
=head1 DESCRIPTION
=head1 METHODS
-=cut
-
=head2 set_multiple $name
Mark the key string C<$name> as containing multiple values.
@@ -384,16 +389,17 @@ sub define {
Return C<value> cast into the type specified by C<as>.
-Valid values for C<as> are C<bool> or C<int>. For C<bool>, C<true>, C<yes>,
-C<on>, C<1>, and undef are translated into a true value; anything else is
-false.
+Valid values for C<as> are C<bool>, C<int>, or C<num>. For C<bool>, C<true>,
+C<yes>, C<on>, C<1>, and undef are translated into a true value; anything else
+is false.
-For C<int>s, if C<value> ends in C<k>, C<m>, or C<g>, it will be multiplied by
-1024, 1048576, and 1073741824, respectively, before being returned.
+For C<int>s and C<num>s, if C<value> ends in C<k>, C<m>, or C<g>, it will be
+multiplied by 1024, 1048576, and 1073741824, respectively, before being
+returned.
-If C<as> is unspecified, C<value> is returned unchanged.
+TODO should numbers be truncated if C<int> is specified?
-XXX TODO
+If C<as> is unspecified, C<value> is returned unchanged.
=cut
@@ -518,8 +524,8 @@ sub dump {
=head2 format_section 'section.subsection'
-Return a formatted string representing how section headers should be printed in
-the config file.
+Return a string containing the section/subsection header, formatted
+as it should appear in a config file.
=cut
@@ -535,6 +541,14 @@ sub format_section {
}
}
+=head2 format_definition( key => 'str', value => 'str', bare => 1 )
+
+Return a string containing the key/value pair as they should be printed in the
+config file. If C<bare> is true, the returned value is not tab-indented nor
+followed by a newline.
+
+=cut
+
sub format_definition {
my $self = shift;
my %args = (
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list