Alien-ROOT
view release on metacpan or search on metacpan
inc/inc_Module-Build/Module/Build/Notes.pm view on Meta::CPAN
=head1 NAME
Module::Build::Notes - Create persistent distribution configuration modules
=head1 DESCRIPTION
This module is used internally by Module::Build to create persistent
configuration files that can be installed with a distribution. See
L<Module::Build::ConfigData> for an example.
=head1 AUTHOR
Ken Williams <kwilliams@cpan.org>
=head1 COPYRIGHT
Copyright (c) 2001-2006 Ken Williams. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 SEE ALSO
perl(1), L<Module::Build>(3)
=cut
__DATA__
package NOTES_NAME;
use strict;
my $arrayref = eval do {local $/; <DATA>}
or die "Couldn't load ConfigData data: $@";
close DATA;
my ($config, $features, $auto_features) = @$arrayref;
sub config { $config->{$_[1]} }
sub set_config { $config->{$_[1]} = $_[2] }
sub set_feature { $features->{$_[1]} = 0+!!$_[2] } # Constrain to 1 or 0
sub auto_feature_names { grep !exists $features->{$_}, keys %$auto_features }
sub feature_names {
my @features = (keys %$features, auto_feature_names());
@features;
}
sub config_names { keys %$config }
sub write {
my $me = __FILE__;
require IO::File;
# Can't use Module::Build::Dumper here because M::B is only a
# build-time prereq of this module
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);
seek($fh, tell($fh), 0);
my $data = [$config, $features, $auto_features];
$fh->print( 'do{ my '
. Data::Dumper->new([$data],['x'])->Purity(1)->Dump()
. '$x; }' );
truncate($fh, tell($fh));
$fh->close;
chmod($mode_orig, $me)
or warn "Couldn't restore permissions on $me: $!";
}
sub feature {
my ($package, $key) = @_;
return $features->{$key} if exists $features->{$key};
my $info = $auto_features->{$key} or return 0;
# Under perl 5.005, each(%$foo) isn't working correctly when $foo
# was reanimated with Data::Dumper and eval(). Not sure why, but
# copying to a new hash seems to solve it.
my %info = %$info;
require Module::Build; # XXX should get rid of this
while (my ($type, $prereqs) = each %info) {
next if $type eq 'description' || $type eq 'recommends';
my %p = %$prereqs; # Ditto here.
while (my ($modname, $spec) = each %p) {
my $status = Module::Build->check_installed_status($modname, $spec);
if ((!$status->{ok}) xor ($type =~ /conflicts$/)) { return 0; }
if ( ! eval "require $modname; 1" ) { return 0; }
}
}
return 1;
}
=begin private
=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
( run in 0.928 second using v1.01-cache-2.11-cpan-fa01517f264 )