[Module-build-checkins] ADDENDUM - a missed change
Status: Beta
Brought to you by:
kwilliams
|
From: Ken W. <ke...@ma...> - 2005-03-25 21:39:55
|
When I committed a recent change to CVS, I got the following message
from sourceforge's SMTP server:
smtplib.SMTPSenderRefused: (452, 'Space shortage, please try later',
'kwi...@pr...')
Here's a summary of the change I committed:
"Move the mammoth write_config_data() method to the Notes class"
Index: lib/Module/Build/Base.pm
===================================================================
RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Base.pm,v
retrieving revision 1.399
retrieving revision 1.400
diff -u -r1.399 -r1.400
--- lib/Module/Build/Base.pm 24 Mar 2005 04:52:42 -0000 1.399
+++ lib/Module/Build/Base.pm 24 Mar 2005 16:36:09 -0000 1.400
@@ -319,137 +319,15 @@
$self->log_info("Writing config notes to $notes_pm\n");
File::Path::mkpath(File::Basename::dirname($notes_pm));
- my $fh = IO::File->new("> $notes_pm") or die "Can't create
'$notes_pm': $!";
- printf $fh <<'EOF', $notes_name;
-package %s;
-use strict;
-my $arrayref = eval do {local $/; <DATA>}
- or die "Couldn't load ConfigData data: $@";
-close DATA;
-my ($config, $features) = @$arrayref;
-
-sub config { $config->{$_[1]} }
-sub feature { $features->{$_[1]} }
-
-sub set_config { $config->{$_[1]} = $_[2] }
-sub set_feature { $features->{$_[1]} = 0+!!$_[2] }
-
-sub feature_names { keys %%$features }
-sub config_names { keys %%$config }
-
-sub write {
- my $me = __FILE__;
- require IO::File;
- require Data::Dumper;
-
- my $mode_orig = (stat $me)[2] & 07777;
- chmod($mode_orig | 0222, $me); # Make it writeable
- my $fh = IO::File->new($me, 'r+') or die "Can't rewrite $me: $!";
- seek($fh, 0, 0);
- while (<$fh>) {
- last if /^__DATA__$/;
- }
- die "Couldn't find __DATA__ token in $me" if eof($fh);
-
- local $Data::Dumper::Terse = 1;
- seek($fh, tell($fh), 0);
- $fh->print( Data::Dumper::Dumper([$config, $features]) );
- truncate($fh, tell($fh));
- $fh->close;
-
- chmod($mode_orig, $me)
- or warn "Couldn't restore permissions on $me: $!";
-}
-
-EOF
-
- printf $fh <<"EOF", $notes_name, $module_name;
-
-=head1 NAME
-
-$notes_name - Configuration for $module_name
-
-=head1 SYNOPSIS
-
- use $notes_name;
- \$value = $notes_name->config('foo');
- \$value = $notes_name->feature('bar');
-
- \@names = $notes_name->config_names;
- \@names = $notes_name->feature_names;
-
- $notes_name->set_config(foo => \$new_value);
- $notes_name->set_feature(bar => \$new_value);
- $notes_name->write; # Save changes
-
-=head1 DESCRIPTION
-
-This module holds the configuration data for the C<$module_name>
-module. It also provides a programmatic interface for getting or
-setting that configuration data. Note that in order to actually make
-changes, you'll have to have write access to the C<$notes_name>
-module, and you should attempt to understand the repercussions of your
-actions.
-
-=head1 METHODS
-
-=over 4
-
-=item config(\$name)
-
-Given a string argument, returns the value of the configuration item
-by that name, or C<undef> if no such item exists.
-
-=item feature(\$name)
-
-Given a string argument, returns the value of the feature by that
-name, or C<undef> if no such feature exists.
-
-=item set_config(\$name, \$value)
-
-Sets the configuration item with the given name to the given value.
-The value may be any Perl scalar that will serialize correctly using
-C<Data::Dumper>. This includes references, objects (usually), and
-complex data structures. It probably does not include transient
-things like filehandles or sockets.
-
-=item set_feature(\$name, \$value)
-
-Sets the feature with the given name to the given boolean value. The
-value will be converted to 0 or 1 automatically.
-
-=item config_names()
-
-Returns a list of all the names of config items currently defined in
-C<$notes_name>, or in scalar context the number of items.
-
-=item feature_names()
-
-Returns a list of all the names of features currently defined in
-C<$notes_name>, or in scalar context the number of features.
-
-=item write()
-
-Commits any changes from C<set_config()> and C<set_feature()> to disk.
-Requires write access to the C<$notes_name> module.
-
-=back
-
-=head1 AUTHOR
-
-C<$notes_name> was automatically created using C<Module::Build>.
-C<Module::Build> was written by Ken Williams, but he holds no
-authorship claim or copyright claim to the contents of C<$notes_name>.
-
-=cut
-
-__DATA__
-
-EOF
-
- local $Data::Dumper::Terse = 1;
- print $fh Data::Dumper::Dumper([scalar $self->config_data, scalar
$self->feature]);
+ Module::Build::Notes->write_config_data
+ (
+ file => $notes_pm,
+ module => $module_name,
+ config_module => $notes_name,
+ config_data => scalar $self->config_data,
+ feature => scalar $self->feature,
+ );
}
{
Index: lib/Module/Build/Notes.pm
===================================================================
RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Notes.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- lib/Module/Build/Notes.pm 24 Mar 2005 04:52:44 -0000 1.2
+++ lib/Module/Build/Notes.pm 24 Mar 2005 16:36:09 -0000 1.3
@@ -6,6 +6,8 @@
use Data::Dumper;
use IO::File;
+use Carp; BEGIN{ $SIG{__DIE__} = \&carp::confess }
+
sub new {
my ($class, %args) = @_;
my $file = delete $args{file} or die "Missing required parameter
'file' to new()";
@@ -95,4 +97,141 @@
print $fh Data::Dumper::Dumper($data);
}
+sub write_config_data {
+ my ($self, %args) = @_;
+
+ my $fh = IO::File->new("> $args{file}") or die "Can't create
'$args{file}': $!";
+
+ printf $fh <<'EOF', $args{config_module};
+package %s;
+use strict;
+my $arrayref = eval do {local $/; <DATA>}
+ or die "Couldn't load ConfigData data: $@";
+close DATA;
+my ($config, $features) = @$arrayref;
+
+sub config { $config->{$_[1]} }
+sub feature { $features->{$_[1]} }
+
+sub set_config { $config->{$_[1]} = $_[2] }
+sub set_feature { $features->{$_[1]} = 0+!!$_[2] }
+
+sub feature_names { keys %%$features }
+sub config_names { keys %%$config }
+
+sub write {
+ my $me = __FILE__;
+ require IO::File;
+ require Data::Dumper;
+
+ my $mode_orig = (stat $me)[2] & 07777;
+ chmod($mode_orig | 0222, $me); # Make it writeable
+ my $fh = IO::File->new($me, 'r+') or die "Can't rewrite $me: $!";
+ seek($fh, 0, 0);
+ while (<$fh>) {
+ last if /^__DATA__$/;
+ }
+ die "Couldn't find __DATA__ token in $me" if eof($fh);
+
+ local $Data::Dumper::Terse = 1;
+ seek($fh, tell($fh), 0);
+ $fh->print( Data::Dumper::Dumper([$config, $features]) );
+ truncate($fh, tell($fh));
+ $fh->close;
+
+ chmod($mode_orig, $me)
+ or warn "Couldn't restore permissions on $me: $!";
+}
+
+EOF
+
+ my ($module_name, $notes_name) = ($args{module},
$args{config_module});
+ printf $fh <<"EOF", $notes_name, $module_name;
+
+=head1 NAME
+
+$notes_name - Configuration for $module_name
+
+=head1 SYNOPSIS
+
+ use $notes_name;
+ \$value = $notes_name->config('foo');
+ \$value = $notes_name->feature('bar');
+
+ \@names = $notes_name->config_names;
+ \@names = $notes_name->feature_names;
+
+ $notes_name->set_config(foo => \$new_value);
+ $notes_name->set_feature(bar => \$new_value);
+ $notes_name->write; # Save changes
+
+=head1 DESCRIPTION
+
+This module holds the configuration data for the C<$module_name>
+module. It also provides a programmatic interface for getting or
+setting that configuration data. Note that in order to actually make
+changes, you'll have to have write access to the C<$notes_name>
+module, and you should attempt to understand the repercussions of your
+actions.
+
+=head1 METHODS
+
+=over 4
+
+=item config(\$name)
+
+Given a string argument, returns the value of the configuration item
+by that name, or C<undef> if no such item exists.
+
+=item feature(\$name)
+
+Given a string argument, returns the value of the feature by that
+name, or C<undef> if no such feature exists.
+
+=item set_config(\$name, \$value)
+
+Sets the configuration item with the given name to the given value.
+The value may be any Perl scalar that will serialize correctly using
+C<Data::Dumper>. This includes references, objects (usually), and
+complex data structures. It probably does not include transient
+things like filehandles or sockets.
+
+=item set_feature(\$name, \$value)
+
+Sets the feature with the given name to the given boolean value. The
+value will be converted to 0 or 1 automatically.
+
+=item config_names()
+
+Returns a list of all the names of config items currently defined in
+C<$notes_name>, or in scalar context the number of items.
+
+=item feature_names()
+
+Returns a list of all the names of features currently defined in
+C<$notes_name>, or in scalar context the number of features.
+
+=item write()
+
+Commits any changes from C<set_config()> and C<set_feature()> to disk.
+Requires write access to the C<$notes_name> module.
+
+=back
+
+=head1 AUTHOR
+
+C<$notes_name> was automatically created using C<Module::Build>.
+C<Module::Build> was written by Ken Williams, but he holds no
+authorship claim or copyright claim to the contents of C<$notes_name>.
+
+=cut
+
+__DATA__
+
+EOF
+
+ local $Data::Dumper::Terse = 1;
+ print $fh Data::Dumper::Dumper([$args{config_data}, $args{feature}]);
+}
+
1;
|