Subject: | Delayed loading of Config::Std breaks the interface |
Should one want to only load Config::Std on demand its aggressive use of
prototypes causes a problem. Curtis was trying to do this today:
require Config::Std;
Config::Std->import;
read_config($file, my %config);
"Scalar second argument to 'read_config' must be empty"
The problem is that read_config employs a reference prototype for its
second argument. Unless read_config() is imported at compile time the
prototype does not apply and the interface is broken. This makes
loading Config::Std on demand difficult.
A work around is to pass in the reference directly rather than rely on
the prototyping. If it stumped Curtis then this is probably worth
noting in the docs. Patch attached.
For future modules its worth considering avoiding reference prototypes
for this reason and also their action-at-a-distance nature (ie. its not
immediately obvious to the caller that %config will be passed by
reference and modified) and long standing prototype ickiness.
Subject: | std.patch |
diff -rN -u old-Config-Std-v0.0.4/lib/Config/Std.pm new-Config-Std-v0.0.4/lib/Config/Std.pm
--- old-Config-Std-v0.0.4/lib/Config/Std.pm 2006-04-10 13:58:34.000000000 -0700
+++ new-Config-Std-v0.0.4/lib/Config/Std.pm 2006-04-10 13:58:34.000000000 -0700
@@ -886,7 +886,23 @@
=head1 BUGS AND LIMITATIONS
-No bugs have been reported.
+=over
+
+=item Loading on demand
+
+Because C<read_config()> and C<write_config()> make use of prototypes
+to turn what seems like a normal variable into a reference, unless
+they are imported at compile time they will not work properly. To
+work around this, pass in the config hash reference manually.
+
+ require Config::Std;
+ Config::Std->import;
+
+ my %config;
+ read_config($file, \%config);
+ write_config(\%config, $file);
+
+=back
Please report any bugs or feature requests to
C<bug-config-std@rt.cpan.org>, or through the web interface at