[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GT] Re: Bug fixes in GT::Conf
Nick Fantes Huege wrote:
When GT/Conf.pm reads the configuration file, it assumes that
statements that end in a backslash continue on the next line. It also
allows for inline comments behind a pound sign.
Currently multi-line statements have to have the \ symbol as their
very last character, otherwise they won't concatenate the next line.
So, for example if you have a couple of spaces after the ending \, it
won't work.
Similar problem with the inline comments. If you have a # Comment
right behind the \ sign, it won't work properly.
Attached is a fixed version of Conf.pm, with this and other minor
modifications. Here is also a Pastebin http://pastebin.com/XZvzWnjY
This module is completely backwards compatible with the old one.
The changes are:
1. Fixed multi-line statements with inline comments
aloha nick
i like the improved handling of continued lines with embedded comments
and the handling of inadvertent whitespace following the '\' char.
but there are a couple of issues to note with the filtering:
using attached new_multiline and the input file ml-options
% new_multiline > & /tmp/new_processed_options.out
the new filter fails to terminate lines continued but 'terminated'
by a trailing blank line (1 or more)
(MULTILINE_TEST line 1 and MULTILINE_TEST line 1d)
the blank line reset is a fallback continuation line reset
i use it frequently especially when 'tweaking' on new aliases ...
the filter is generating an extraneous key named '#' with a null value
(''key:#: val::'')
as an alternate test approach review perl script new_conf_dump.pl:
with the new GT::Conf::load sub appended onto ../GT/Conf.pm and
renamed GT::Conf::new_load (or a similar adjustment) one can do a
direct comparison of differences between these load versions using
the GT::Conf::conf_dump() method. this is probably a better way to
verify the functionality of a GT::Conf::load replacement.
2. Improved _get_home_path function (for Windows)
3. Added sub vars which returns a hash_ref to all config options.
Sometimes it's easier to use $conf->{'db::module'} instead
>::Conf::get('DB::module'), because the former can be interpolated
in strings.
is there an example of item 3 you want to point out?
4. Minor code reorders and improvements.
Note that I have removed all comments and pod from the module, because
for some reason they mess up my debugger.
If you find this patch to be useful, please feel free to add all the
commends and pod back.
this removal is rather annoying -- makes for a lot more work ...
isn't there a way you can work around this?
Best regards,
Nick
<snip>
ras
#!/usr/bin/perl
my %conf;
# comment out to use your $HOME/.gt/options file
$file="./ml-options";
$file = $ENV{'HOME'} . "/.gt/options" unless defined $file;
die "file $file not found\n" unless -e $file;
# following is preferred -- ref. pg 625 programming perl 3rd ed.
open (FILE, "<", "$file") or die "Can't open $file: $!\n";
my $line = '';
while (<FILE>) {
chop while /(\n|\r|\s)$/;
s/^\s+//;
s/\s*#\D+.*$//;
next unless $_;
$line .= $_;
next if $line =~ s/\\$/ /;
$line =~ tr/[ \t]/[ \t]/s;
my ( $key, $val ) = split /\s+/, $line, 2;
$conf{ lc($key) } = $val;
$line = '';
}
close FILE;
while ( my ( $keyx, $data ) = each %conf ) {
print STDERR "key:$keyx:\tval:$data:\n";
}
#
# genius trader options file
#
# define which database server (mysql or postgresql)
DB::module bean
# following is line with whitespace
# these next 2 continued lines s/b 'terminated' by trailing blank line
MULTILINE_TEST line 1\
line 2 \
line 3 \
MULTILINE_TEST line 1d\
line 1d2 \
line 1d3 \
MULTILINE_TESTb line 1b\
line 2b \
line 3b
MULTILINE_TESTc\
line 1c \
line 2c\
line 3c
Graphic::BackgroundColor [255,200,255] # # horrid purple pink
Graphic::ForegroundColor [255,200,255] # # horrid purple pink
Graphic::Positions::BuyColor "[0,135,0]" # very dark green
Graphic::Volume::Color I:G:If \# this will volume bar color
{S:G:Below {I:Prices OPEN} {I:Prices CLOSE}} green red
Aliases::Global::TFS2[] SY:TFS #1 #2 \ # 1 is asfd, 2 is sdafasd
| CS:SY:TFS #1 # 1 defaults to asfsfsds
# commented out lines
#Aliases::Indicators::i_ibd_rally I:G:If { @S:s_ibd_rally 1.6 1.6 } \
{ I:G:Eval {I:Prices LOW} - 100 } \
{ I:G:Eval sprintf qq[] }
#Aliases::Indicators::i_ibd_rally I:G:If { @S:s_ibd_rally 1.6 1.6 } \
{ I:G:Eval {I:Prices LOW} - { I:G:Eval {I:Prices LOW} * 0.04 } } \
{ I:G:Eval sprintf qq[] }
Aliases::Indic I:G:If { @S:s_ibd_rally 1.6 1.6 } \
{ I:G:Eval {I:Prices LOW} - { I:G:Eval {I:Prices LOW} * 0.04 } } \
{ I:G:Eval sprintf qq[] }
#Aliases::Indicators::i_ibd_rally I:G:If { @S:s_ibd_rally 1.6 1.6 } \
{ I:G:Eval {I:Prices LOW} - 100 } \
{ I:G:Eval sprintf qq[] }
# end
#!/usr/local/bin/perl -w
# use Test::Simple tests => 1;
#
# ok( 1 + 1 == 2 );
# ok( 2 + 2 == 5 );
# use Test::Simple tests => 2;
#
# use Date::ICal;
#
# my $ical = Date::ICal->new; # create an object
# ok( defined $ical ); # check that we got something
# ok( $ical->isa('Date::ICal') ); # and it's the right class
use Test::More 'no_plan';
use Test::Differences;
use lib '..';
#use GT::Conf;
BEGIN { use_ok 'GT::Conf'; }
my $opt_file;
$opt_file = './ml-options';
$opt_file = $ENV{'HOME'} . "/.gt/options" unless $opt_file;
GT::Conf::clear();
GT::Conf::load( "$opt_file" );
print "processed using current load filtering\n";
GT::Conf::conf_dump();
GT::Conf::clear();
GT::Conf::new_load( "$opt_file" );
print "processed using nicks new load filtering\n";
GT::Conf::conf_dump();