Update of /cvsroot/module-build/Module-Build/lib/Module/Build
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8299/lib/Module/Build
Modified Files:
Base.pm
Log Message:
Extend property accessors for hashes to allow easy access to elements.
Index: Base.pm
===================================================================
RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Base.pm,v
retrieving revision 1.521
retrieving revision 1.522
diff -u -d -r1.521 -r1.522
--- Base.pm 19 Nov 2005 04:36:48 -0000 1.521
+++ Base.pm 21 Nov 2005 01:21:09 -0000 1.522
@@ -342,8 +342,6 @@
return;
}
-sub base_dir { shift()->{properties}{base_dir} }
-
sub _is_interactive {
return -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ; # Pipe?
}
@@ -516,17 +514,44 @@
$valid_properties{$class}{$property} = $default;
- if (my $type = ref $default) {
+ my $type = ref $default;
+ if ($type) {
push @{$additive_properties{$class}->{$type}}, $property;
}
unless ($class->can($property)) {
no strict 'refs';
- *{"$class\::$property"} = sub {
- my $self = shift;
- $self->{properties}{$property} = shift if @_;
- return $self->{properties}{$property};
- };
+ if ( $type eq 'HASH' ) {
+ *{"$class\::$property"} = sub {
+ my $self = shift;
+ my $x = ( $property eq 'config' ) ? $self : $self->{properties};
+ return $x->{$property} unless @_;
+
+ if ( defined($_[0]) && !ref($_[0]) ) {
+ if ( @_ == 1 ) {
+ return exists( $x->{$property}{$_[0]} ) ?
+ $x->{$property}{$_[0]} : undef;
+ } elsif ( @_ % 2 == 0 ) {
+ my %args = @_;
+ while ( my($k, $v) = each %args ) {
+ $x->{$property}{$k} = $v;
+ }
+ } else {
+ die "Unexpected arguments for property '$property'\n";
+ }
+ } else {
+ $x->{$property} = $_[0];
+ }
+ };
+
+ } else {
+ *{"$class\::$property"} = sub {
+ my $self = shift;
+ $self->{properties}{$property} = shift if @_;
+ return $self->{properties}{$property};
+ }
+ }
+
}
return $class;
}
@@ -834,13 +859,6 @@
$self->{phash}{$_}->write() foreach qw(notes cleanup features auto_features config_data runtime_params);
}
-sub config { shift()->{config} }
-
-sub requires { shift()->{properties}{requires} }
-sub recommends { shift()->{properties}{recommends} }
-sub build_requires { shift()->{properties}{build_requires} }
-sub conflicts { shift()->{properties}{conflicts} }
-
sub check_autofeatures {
my ($self) = @_;
my $features = $self->auto_features;
|