Skip to content

Commit

Permalink
Assign to intermediate variable rather than to sub's argument.
Browse files Browse the repository at this point in the history
Within a subroutine, assigning to a hash passed to that sub as an argument is
a recipe for confusion.  In compile(), create an intermediate variable for
clearer handling of the object file.  Use a ternary rather than an if-else,
for terser code.  Restore use of arg_object_file() now that we have debugged.
  • Loading branch information
jkeenan committed May 16, 2010
1 parent ca36f4d commit 779bbc4
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions lib/ExtUtils/CBuilder/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,23 @@ sub compile {
my $cf = $self->{config}; # For convenience
my @cc = $self->split_like_shell($cf->{cc});

$args{object_file} ||= $self->object_file($args{source});

my $include_dirs_ref = [];
if (exists($args{include_dirs}) && ref($args{include_dirs}) ne "ARRAY") {
$include_dirs_ref = [ $args{include_dirs} ];
}
else {
$include_dirs_ref = $args{include_dirs};
}


my $object_file = $args{object_file}
? $args{object_file}
: $self->object_file($args{source});

my $include_dirs_ref =
(exists($args{include_dirs}) && ref($args{include_dirs}) ne "ARRAY")
? [ $args{include_dirs} ]
: $args{include_dirs};
my @include_dirs = $self->arg_include_dirs(
@{ $include_dirs_ref || [] },
$self->perl_inc(),
);

my @defines = $self->arg_defines( %{$args{defines} || {}} );

my @extra_compiler_flags = $self->split_like_shell($args{extra_compiler_flags});
my @extra_compiler_flags =
$self->split_like_shell($args{extra_compiler_flags});
my @cccdlflags = $self->split_like_shell($cf->{cccdlflags});
my @ccflags = $self->split_like_shell($cf->{ccflags});
push @ccflags, qw/-x c++/ if $args{'C++'};
Expand All @@ -121,17 +119,14 @@ sub compile {
$self->arg_nolink,
@ccflags,
@optimize,
'-o',
$args{object_file},
$self->arg_object_file($object_file),
);

my @all_args = (@cc, @flags, $args{source});
#say STDERR Dumper \@all_args;
$self->do_system(@all_args)
or die "error building $args{object_file} from '$args{source}'";
# or die "error building $object_file from '$args{source}'";
or die "error building $object_file from '$args{source}'";

return $args{object_file};
return $object_file;
}

sub have_compiler {
Expand Down

0 comments on commit 779bbc4

Please sign in to comment.