[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GT] Proposed patch for Indicators::new()
- To: devel <devel
AT
geniustrader.org>
- Subject: [GT] Proposed patch for Indicators::new()
- From: Nick Fantes Huege <nfhuege
AT
gmail.com>
- Date: Thu, 22 Jul 2010 17:55:14 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=caxf1WhMqps9rwh676hX+j2TX+AocjN7Of7MxOSq2CI=; b=arPpo0BRKzx2zmXlGbbMJqrTa0nX3DZ1y4Ft9K9aXqpMOXJ0JxLsBUHzswHnelraMk AfX5upH9gk3ugjCvG74cM94nATWWeD0pyxTQ9FEqKm74m3dVTo6t5lwl6NsQL0SvaKo9 nhKertKmMwijss38GZyeBYQX3oUTyjFI4gK/0=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=Wwg6MIX5hyCFDWdua3J+XS22KYicxZl2tM1IcBbHahcMM2byNJYstGOxa6/Gi1cbVy H388ZtV+G5VR6PMGZtotG7wkg0ARb3cy03hHGNg+Yo0KvVALCG1wVjmju1sE4fFZT3/u 80nw4h/UUdymWmHGdShnAD5A+ay/o77jDz+70=
- Message-id: <AANLkTimzzTHv7Zya73Pp7F5DmVlrZf9hb7UjZW0RZdld@mail.gmail.com> (sfid-20100722_165634_491061_18A2BE7B)
- Reply-to: devel
AT
geniustrader.org
The constructor function 'new' for GT::Indicators attempts to
reference the variable $args in a slightly illegal way. To avoid an
interpreter error the author has added 'no strict "refs"' to the code.
To improve compatibility and to keep "strict" turned on at all times,
I have modified the sub as follows:
===== OLD VERSION =====
sub new {
my ($type, $args, $key, $func) = @_;
my $class = ref($type) || $type;
no strict "refs";
my $self = {};
if (defined($args)) {
if ( $#{$args} < $#{"$class\::DEFAULT_ARGS"} ) {
for (my $n=($#{$args}+1); $n<=$#{"$class\::DEFAULT_ARGS"}; $n++) {
push @{$args}, ${"$class\::DEFAULT_ARGS"}[$n];
}
}
$self->{'args'} = GT::ArgsTree->new(@{$args});
} elsif (defined (@{"$class\::DEFAULT_ARGS"})) {
$self->{'args'} = GT::ArgsTree->new(@{"$class\::DEFAULT_ARGS"});
} else {
$self->{'args'} = GT::ArgsTree->new(); # no args
}
if (defined($func)) {
die "We tried to pass a 'func' parameter to an indicator,
please convert the module...";
}
$self->{'func'} = sub { die "Please convert this module to NOT use
\$self->{'func'} ..."; };
return manage_object(\
AT
{"$class\::NAMES"}, $self, $class,
$self->{'args'}, $key);
}
===== END OF OLD VERSION =====
===== NEW VERSION ====
sub new {
my ( $type, $args, $key, $func ) = @_;
my $class = ref($type) || $type;
my $self = {}; $args ||= [];
my @DEFAULTS; eval("\
AT
DEFAULTS = \
AT
$class\::DEFAULT_ARGS");
splice( @DEFAULTS, 0, scalar(@$args) );
push @$args, @DEFAULTS;
$self->{'args'} = GT::ArgsTree->new( @$args );
if ( defined($func) ) {
die "We tried to pass a 'func' parameter to an indicator,
please convert the module...";
}
$self->{'func'} = sub {
die "Please convert this module to NOT use \$self->{'func'} ..."
};
my @NAMES; eval("\
AT
NAMES = \
AT
$class\::NAMES");
return &manage_object( \
AT
NAMES, $self, $class, $self->{'args'}, $key );
}
===== END OF NEW VERSION ====
Both versions of the sub work equally well. The new one is just a
little tighter and more compatible.
Regards,
Nick