Parse-PlainConfig-3.07/0000750000175000001440000000000014547616507014454 5ustar acorlissusersParse-PlainConfig-3.07/t/0000750000175000001440000000000014547616507014717 5ustar acorlissusersParse-PlainConfig-3.07/t/v2_11_order.t0000644000175000001440000000210312741127445017120 0ustar acorlissusers# 11_order.t # # Tests the order method use Parse::PlainConfig::Legacy; $|++; print "1..2\n"; my $test = 1; my $conf = new Parse::PlainConfig::Legacy; my $nconf = new Parse::PlainConfig::Legacy; my $testrc = "./t/v2_testrc"; $conf->coerce('string', 'SCALAR 5'); $conf->read($testrc); # 1 change order and write w/smart $conf->property("SMART_PARSER", 1); $conf->coerce('string', 'SCALAR 1', 'SCALAR 2', 'SCALAR 3', 'SCALAR 4', 'SCALAR 5'); $conf->coerce('list', 'LIST 1', 'LIST 2', 'LIST 3'); $conf->coerce('hash', 'HASH 1'); $conf->order('HASH 1', 'LIST 3', 'SCALAR 5'); $rv = $conf->write("${testrc}_order"); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # 2 read and compare order $nconf->property("SMART_PARSER", 1); $nconf->coerce('string', 'SCALAR 1', 'SCALAR 2', 'SCALAR 3', 'SCALAR 4', 'SCALAR 5'); $nconf->coerce('list', 'LIST 1', 'LIST 2', 'LIST 3'); $nconf->coerce('hash', 'HASH 1'); $nconf->read("${testrc}_order"); ($nconf->order)[0] eq 'HASH 1' ? print "ok $test\n" : print "not ok $test\n"; unlink "${testrc}_order"; $test++; # end 11_order.t Parse-PlainConfig-3.07/t/v2_03_read.t0000644000175000001440000000065012741127445016726 0ustar acorlissusers#!/usr/bin/perl -T # 03_read.t use Test::More tests => 3; use Paranoid; use Parse::PlainConfig::Legacy; use strict; use warnings; psecureEnv(); my $testrc = "./t/v2_testrc"; my $conf = new Parse::PlainConfig::Legacy; my @p; ok( !$conf->read( "${testrc}-1" ), 'read 1' ); ok( $conf->read( $testrc ), 'read 2' ); @p = $conf->parameters; is( scalar( grep( /^SCALAR 1$/, @p ) ), 1, 'check parameters' ); # end 03_read.t Parse-PlainConfig-3.07/t/v3_02_init.t0000644000175000001440000000047012741127445016756 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 2; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use MyConf; #PDEBUG = 20; my $obj = new MyConf; ok( defined $obj, 'new object - 1' ); ok( length $obj->default, 'conf default - 1' ); Parse-PlainConfig-3.07/t/v2_13_readIfNewer.t0000644000175000001440000000244212741127445020210 0ustar acorlissusers# 13_readIfNewer.t # # Tests the readIfNewer method use Parse::PlainConfig::Legacy; $|++; print "1..8\n"; my $test = 1; my $conf1 = new Parse::PlainConfig::Legacy; my $conf2 = new Parse::PlainConfig::Legacy; my $testrc = "./t/v2_testrc-tmp"; my $rv; # 1 & 2 Load & write to temp file $rv = $conf1->read("./t/v2_testrc"); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; $rv = $conf1->write($testrc); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; $conf1->property(FILE => $testrc); # 3 Load conf2 w/temp file $rv = $conf2->read($testrc); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # 4 Write new value w/conf1 sleep 3; $conf1->parameter("FOO" => "BAR"); $rv = $conf1->write; $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # 5 Reread w/conf2 sleep 3; $rv = $conf2->readIfNewer; $rv == 1 ? print "ok $test\n" : print "not ok $test\n"; $test++; # 6 Make sure new value is there grep(/^FOO$/, $conf2->parameters) ? print "ok $test\n" : print "not ok $test\n"; $test++; # 7 Reread once more sleep 1; $rv = $conf2->readIfNewer; $rv == 2 ? print "ok $test\n" : print "not ok $test\n"; $test++; # 8 Unlink file and reread unlink $testrc; $rv = $conf2->readIfNewer; $rv ? print "not ok $test\n" : print "ok $test\n"; $test++; # end 13_readIfNewer.t Parse-PlainConfig-3.07/t/v2_16_hasParameter.t0000644000175000001440000000135712741127445020440 0ustar acorlissusers# 16_hasParameter.t # # Tests the traditional usage for backwards compatibility use Parse::PlainConfig::Legacy; $|++; print "1..3\n"; my $test = 1; my $conf = new Parse::PlainConfig::Legacy; my $testrc = "./t/v2_testrc"; my ($val, $val2); $conf->read($testrc); $conf->property(DEFAULTS => { NOT_PRESENT => 1, }); # 1 Test key that exists in the defaults hash $rv = $conf->hasParameter('NOT_PRESENT'); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # 2 Test present key $rv = $conf->hasParameter('SCALAR 1'); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # 3 Test invalid key $rv = ! $conf->hasParameter('NOT_THERE'); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # end 16_hasParameter.t Parse-PlainConfig-3.07/t/lib/0000750000175000001440000000000014547616507015465 5ustar acorlissusersParse-PlainConfig-3.07/t/lib/mac.conf0000644000175000001440000000130012741127445017063 0ustar acorlissusers// Okay, this is only a little C'ish, I'm mixing my language memes a // wee bit. // // admin email: email address of the admin admin email := foo@bar.com // db: host, database, username, and password for database access db := host->dbhost, database->mydb.db, username->dbsuperuser, password->dbsuperpass // hosts: list of hosts to monitor hosts := host1.foo.com,host1.bar.com note := This is a note, but not a very long note. With this odd selection of delimiters it looks even more weird. EOF // Let's throw some random ACLs out there declare acl loopback := 127.0.0.1,localhost declare acl localnet := 192.168.0.0/24,192.168.35.0/24 Parse-PlainConfig-3.07/t/lib/MyConf.pm0000644000175000001440000000300112741127445017205 0ustar acorlissuserspackage MyConf; use strict; use warnings; use Parse::PlainConfig; use Parse::PlainConfig::Constants; use base qw(Parse::PlainConfig); use vars qw(%_globals %_parameters %_prototypes); %_globals = ( comment => ';', 'delimiter' => ' ', 'list delimiter' => ':', 'hash delimiter' => '@', 'subindentation' => 4, ); %_parameters = ( 'admin email' => PPC_SCALAR, 'db' => PPC_HASH, 'hosts' => PPC_ARRAY, 'note' => PPC_HDOC, 'nodefault' => PPC_SCALAR, ); %_prototypes = ( 'declare acl' => PPC_ARRAY, 'declare foo' => PPC_SCALAR ); 1; __DATA__ ; This is a sample conf file that not only provides a reference config but ; also supplies the default values of any parameter not explicitly set below. ; ; admin email: email address of the admin admin email root@localhost ; db: host, database, username, and password for database access db host @ localhost : database @ sample.db : username @ dbuser : password @ dbpass ; hosts: list of hosts to monitor hosts localhost:host1.foo.com:host1.bar.com note This is a note, but not a very long note. With this odd selection of delimiters it looks even more weird. EOF ; Let's throw some random ACLs out there declare acl loopback 127.0.0.1:localhost declare acl localnet 192.168.0.0/24:192.168.35.0/24 ; nodefault is just a scalar parameter that has no default setting declare foo bar roo __END__ =head2 POD STARTS HERE Arg! Parse-PlainConfig-3.07/t/lib/CStyle.pm0000644000175000001440000000262212741127445017225 0ustar acorlissuserspackage CStyle; use strict; use warnings; use Parse::PlainConfig; use Parse::PlainConfig::Constants; use base qw(Parse::PlainConfig); use vars qw(%_globals %_parameters %_prototypes); %_globals = ( comment => '//', 'delimiter' => ':=', 'list delimiter' => ',', 'hash delimiter' => '->', 'subindentation' => 4, ); %_parameters = ( 'admin email' => PPC_SCALAR, 'db' => PPC_HASH, 'hosts' => PPC_ARRAY, 'note' => PPC_HDOC, 'nodefault' => PPC_SCALAR, ); %_prototypes = ( 'declare acl' => PPC_ARRAY, 'declare foo' => PPC_SCALAR ); 1; __DATA__ // Okay, this is only a little C'ish, I'm mixing my language memes a // wee bit. // // admin email: email address of the admin admin email := root@localhost // db: host, database, username, and password for database access db := host->localhost, database->sample.db, username->dbuser, password->dbpass // hosts: list of hosts to monitor hosts := localhost,host1.foo.com,host1.bar.com note := This is a note, but not a very long note. With this odd selection of delimiters it looks even more weird. EOF // Let's throw some random ACLs out there declare acl loopback := 127.0.0.1,localhost declare acl localnet := 192.168.0.0/24,192.168.35.0/24 // nodefault is just a scalar parameter that has no default setting Parse-PlainConfig-3.07/t/lib/NoDefaults.pm0000644000175000001440000000117212741127445020065 0ustar acorlissuserspackage NoDefaults; use strict; use warnings; use Parse::PlainConfig; use Parse::PlainConfig::Constants; use base qw(Parse::PlainConfig); use vars qw(%_globals %_parameters %_prototypes); %_globals = ( comment => ';', 'delimiter' => ' ', 'list delimiter' => ':', 'hash delimiter' => '@', 'subindentation' => 4, ); %_parameters = ( 'admin email' => PPC_SCALAR, 'db' => PPC_HASH, 'hosts' => PPC_ARRAY, 'note' => PPC_HDOC, 'nodefault' => PPC_SCALAR, ); %_prototypes = ( 'declare acl' => PPC_ARRAY, 'declare foo' => PPC_SCALAR ); 1; Parse-PlainConfig-3.07/t/lib/01_include_me.conf0000644000175000001440000000010512741127445020731 0ustar acorlissusers// Let's actually assign something to nodefault nodefault := whoops! Parse-PlainConfig-3.07/t/lib/BadConf.pm0000644000175000001440000000277512741127445017327 0ustar acorlissuserspackage BadConf; use strict; use warnings; use Parse::PlainConfig; use Parse::PlainConfig::Constants; use base qw(Parse::PlainConfig); use vars qw(%_globals %_parameters %_prototypes); %_globals = ( comment => ';', 'delimiter' => ' ', 'list delimiter' => ':', 'hash delimiter' => '@', 'subindentation' => 4, ); %_parameters = ( 'admin email' => PPC_SCALAR, 'db' => PPC_HASH, 'hosts' => PPC_ARRAY, 'note' => PPC_HDOC, 'nodefault' => PPC_SCALAR, ); %_prototypes = ( 'declare acl' => PPC_ARRAY, 'declare foo' => PPC_SCALAR ); 1; __DATA__ ; This is a sample conf file that not only provides a reference config but ; also supplies the default values of any parameter not explicitly set below. ; ; admin email: email address of the admin admin email root@localhost ; db: host, database, username, and password for database access db host @ localhost : database @ sample.db : username @ dbuser : password @ dbpass ; hosts: list of hosts to monitor hosts localhost:host1.foo.com:host1.bar.com note This is a note, but not a very long note. With this odd selection of delimiters it looks even more weird. EOF ; Let's throw some random ACLs out there declare acl loopback 127.0.0.1:localhost declare acl localnet 192.168.0.0/24:192.168.35.0/24 ; nodefault is just a scalar parameter that has no default setting ; Let's throw in some non-existent parameters foo bar Parse-PlainConfig-3.07/t/lib/MyConf2.pm0000644000175000001440000000121014503430166017262 0ustar acorlissuserspackage MyConf2; use strict; use warnings; use Parse::PlainConfig; use Parse::PlainConfig::Constants; use MyConf; use base qw(MyConf); use vars qw(%_globals %_parameters %_prototypes); %_parameters = ( 'random thought' => PPC_SCALAR, ); %_prototypes = ( 'declare bar' => PPC_SCALAR ); 1; __DATA__ ; This is a sample conf file that not only provides a reference config but ; also supplies the default values of any parameter not explicitly set below. ; ; admin email: email address of the admin admin email root@yourhost random thought 3.14 declare foo bar roo declare bar foo roo __END__ =head2 POD STARTS HERE Arg! Parse-PlainConfig-3.07/t/lib/unix.conf0000644000175000001440000000134112741127445017313 0ustar acorlissusers// Okay, this is only a little C'ish, I'm mixing my language memes a // wee bit. // // admin email: email address of the admin admin email := foo@bar.com // db: host, database, username, and password for database access db := host->dbhost, database->mydb.db, username->dbsuperuser, password->dbsuperpass // hosts: list of hosts to monitor hosts := host1.foo.com,host1.bar.com note := This is a note, but not a very long note. With this odd selection of delimiters it looks even more weird. EOF // Let's throw some random ACLs out there declare acl loopback := 127.0.0.1,localhost declare acl localnet := 192.168.0.0/24,192.168.35.0/24 include t/lib/*_include_me.conf Parse-PlainConfig-3.07/t/lib/msdos.conf0000644000175000001440000000133212741127445017455 0ustar acorlissusers// Okay, this is only a little C'ish, I'm mixing my language memes a // wee bit. // // admin email: email address of the admin admin email := foo@bar.com // db: host, database, username, and password for database access db := host->dbhost, database->mydb.db, username->dbsuperuser, password->dbsuperpass // hosts: list of hosts to monitor hosts := host1.foo.com,host1.bar.com note := This is a note, but not a very long note. With this odd selection of delimiters it looks even more weird. EOF // Let's throw some random ACLs out there declare acl loopback := 127.0.0.1,localhost declare acl localnet := 192.168.0.0/24,192.168.35.0/24 Parse-PlainConfig-3.07/t/v3_01_constants.t0000644000175000001440000000045512741127445020031 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 3; use Paranoid; use Parse::PlainConfig::Constants; use Class::EHierarchy qw(:all); use strict; use warnings; psecureEnv(); is( PPC_SCALAR, CEH_SCALAR, 'PPC_SCALAR' ); is( PPC_ARRAY, CEH_ARRAY, 'PPC_ARRAY' ); is( PPC_HASH, CEH_HASH, 'PPC_HASH' ); Parse-PlainConfig-3.07/t/v2_testrc_smart0000644000175000001440000000074512741127445017766 0ustar acorlissusers# Scalar tests SCALAR 1: value1 SCALAR 2: "these, are, all one => value" SCALAR 3: this is a continued line. SCALAR 4: ASDFKAS234123098ASDFA9082341 ASDFIO23489078907SFASDF8A972 # List tests LIST 1: value1, value2, value3 LIST 2: value1, "two, parts", value3, "\"two => parts\"" LIST 3: value1, "two, parts", two => parts # Hash tests HASH 1: one => 1, two => 2, three => "Three for Me! 3 => 2", four => 4 Parse-PlainConfig-3.07/t/v2_15_defaults.t0000644000175000001440000000110312741127445017617 0ustar acorlissusers# 15_defaults.t # # Test the defaults capability use Parse::PlainConfig::Legacy; $|++; print "1..2\n"; my $test = 1; my $conf = new Parse::PlainConfig::Legacy; my $testrc = "./t/v2_testrc"; my ($val, $val2); $conf->read($testrc); $conf->property(DEFAULTS => { NOT_PRESENT => 1, }); # 1 Test defaults $val = $conf->parameter('NOT_PRESENT'); $val == 1 ? print "ok $test\n" : print "not ok $test\n"; $test++; # 2 Test present key $val = $conf->parameter('SCALAR 1'); $val eq 'value1' ? print "ok $test\n" : print "not ok $test\n"; $test++; # end 15_defaults.t Parse-PlainConfig-3.07/t/v3_06_c_style.t0000644000175000001440000000301012741127445017452 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 19; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use CStyle; #PDEBUG = 20; my $obj = new CStyle; ok( defined $obj, 'new object - 1' ); my $val = $obj->get('admin email'); is( $val, 'root@localhost', 'default scalar retrieval' ); my @val = $obj->get('hosts'); is( $val[0], 'localhost', 'default array retrieval' ); my %val = $obj->get('db'); is( $val{database}, 'sample.db', 'default hash retrieval' ); $val = $obj->get('note'); ok( length $val, 'default hdoc retrieval' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval' ); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval' ); ok( $obj->set('nodefault', 'set'), 'set parameter'); $val = $obj->get('nodefault'); is( $val, 'set', 'get parameter' ); ok( $obj->set('loopback', $obj->get('localnet')), 'set prototype'); ($val) = $obj->get('loopback'); is( $val, '192.168.0.0/24', 'get prototype'); ok($obj->reset, 'reset config'); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval 2' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval 2' ); #PDEBUG = 9; ok(! $obj->parse('gack! Spurious text!!!'), 'spurious text 1'); ok(! $obj->parse('declare acl db := foo'), 'proto/prop conflict 1'); ok(! $obj->parse('declare foo localnet := bar'), 'proto/prop conflict 2'); ok(! $obj->set('admin user', 'foo'), 'invalid prop 1'); ok(! $obj->get('admin user'), 'invalid prop 2'); Parse-PlainConfig-3.07/t/v3_11_subclass-parameters.t0000644000175000001440000000376314503723447022005 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 25; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use MyConf2; #PDEBUG = 20; my $obj = new MyConf2; ok( defined $obj, 'new object - 1' ); my $val = $obj->get('admin email'); is( $val, 'root@yourhost', 'default scalar retrieval' ); my @val = $obj->get('hosts'); is( $val[0], 'localhost', 'default array retrieval' ); my %val = $obj->get('db'); is( $val{database}, 'sample.db', 'default hash retrieval' ); $val = $obj->get('note'); ok( length $val, 'default hdoc retrieval' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval' ); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval' ); ok( $obj->set( 'nodefault', 'set' ), 'set parameter' ); $val = $obj->get('nodefault'); is( $val, 'set', 'get parameter' ); ok( $obj->set( 'loopback', $obj->get('localnet') ), 'set prototype' ); ($val) = $obj->get('loopback'); is( $val, '192.168.0.0/24', 'get prototype' ); $val = [ $obj->prototyped ]; is( scalar @$val, 4, 'prototyped all 1' ); ok( ( scalar grep { $_ eq 'loopback' } @$val ), 'prototyped all 2' ); $val = [ $obj->prototyped('declare acl') ]; is( scalar @$val, 2, 'prototyped specific 1' ); ok( ( scalar grep { $_ eq 'loopback' } @$val ), 'prototyped specific 2' ); $val = [ $obj->prototyped('declare foo') ]; is( scalar @$val, 1, 'prototyped specific 3' ); ok( ( scalar grep { $_ eq 'bar' } @$val ), 'prototyped specific 4' ); ok( $obj->reset, 'reset config' ); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval 2' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval 2' ); #PDEBUG = 9; ok( !$obj->parse('gack! Spurious text!!!'), 'spurious text 1' ); ok( !$obj->parse('declare acl db foo'), 'proto/prop conflict 1' ); ok( !$obj->parse('declare foo localnet bar'), 'proto/prop conflict 2' ); ok( !$obj->set( 'admin user', 'foo' ), 'invalid prop 1' ); ok( !$obj->get('admin user'), 'invalid prop 2' ); Parse-PlainConfig-3.07/t/v2_04_parameters.t0000644000175000001440000000116612741127445020162 0ustar acorlissusers#!/usr/bin/perl -T # 04_parameters.t use Test::More tests => 8; use Paranoid; use Parse::PlainConfig::Legacy; use strict; use warnings; psecureEnv(); my $testrc = "./t/v2_testrc"; my $conf = Parse::PlainConfig::Legacy->new(FILE => $testrc); my @test = ("SCALAR 1", "SCALAR 2", "SCALAR 3", "LIST 1", "LIST 2", "HASH 1"); my (@params, $p); # 1 Make sure parameters have been read ok( $conf->read, 'read 1'); @params = $conf->parameters; is( scalar(@params), 10, '# of parameters read' ); foreach my $t (@test) { ($p) = grep /^\Q$t\E$/, @params; is( $p, $t, "parameter $t" ); } # end 04_parameters.t Parse-PlainConfig-3.07/t/v2_07_list.t0000644000175000001440000000401612741127445016772 0ustar acorlissusers# 07_list.t # # Tests for proper extraction of scalar values use Parse::PlainConfig::Legacy; $|++; print "1..10\n"; my $test = 1; my $rcfile = './t/v2_testrc'; my $conf = Parse::PlainConfig::Legacy->new(FILE => $rcfile); # First series with smart parser off # # 1 list 1 $conf->read($rcfile); ($conf->parameter("LIST 1"))[2] eq "value3" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 2 list 2 ($conf->parameter("LIST 2"))[1] eq "two, parts" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 3 list 3 ($conf->parameter("LIST 3"))[2] eq "two => parts" ? print "ok $test\n" : print "not ok $test\n"; $test++; # Second series with smart parser on # # 4 list 1 $conf->property(SMART_PARSER => 1); $conf->property(AUTOPURGE => 1); $conf->read("${rcfile}_smart"); ($conf->parameter("LIST 1"))[2] eq "value3" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 5 list 2 ($conf->parameter("LIST 2"))[1] eq "two, parts" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 6 list 3 with list coercion set and smart parsing $conf->coerce("list", "LIST 3"); $conf->read; ($conf->parameter("LIST 3"))[2] eq "two => parts" ? print "ok $test\n" : print "not ok $test\n"; $test++; # Set tests # # 7 new list 1 $conf->parameter("NEW LIST 1", [qw(this is a new list)]); ($conf->parameter("NEW LIST 1"))[2] eq "a" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 8 new list 2 with coercion set $conf->coerce("list", "NEW LIST 2"); $conf->parameter("NEW LIST 2", [qw(this is a new list)]); ($conf->parameter("NEW LIST 2"))[2] eq "a" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 9 new list 2 with string value $conf->parameter("NEW LIST 2", "this is new"); ($conf->parameter("NEW LIST 2"))[0] eq "this is new" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 10 new list 2 with hash value $conf->parameter("NEW LIST 2", { 'this' => 'is', 'also' => 'new' }); ($conf->parameter("NEW LIST 2"))[2] eq "this" ? print "ok $test\n" : print "not ok $test\n"; $test++; # end 07_list.t Parse-PlainConfig-3.07/t/98_pod_coverage.t0000644000175000001440000000041112741127444020051 0ustar acorlissusers#!/usr/bin/perl -T use Paranoid; use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok( { private => [ qr/^_/, qr/^[DI]LEVEL$/, qr/^PDINDIGNORED$/ ] } ); Parse-PlainConfig-3.07/t/v2_05_purge.t0000644000175000001440000000202012741127445017130 0ustar acorlissusers#!/usr/bin/perl -T # 05_purge.t use Test::More tests => 10; use Paranoid; use Parse::PlainConfig::Legacy; use strict; use warnings; psecureEnv(); my $testrc = "./t/v2_testrc"; my $conf = Parse::PlainConfig::Legacy->new(FILE => $testrc); my (@params, $p); ok( $conf->read, 'read 1' ); @params = $conf->parameters; ok( scalar @params > 1, 'has parameters 1' ); ok( $conf->purge, 'purge 1'); @params = $conf->parameters; ok( scalar @params == 0, 'has parameters 2' ); $conf = Parse::PlainConfig::Legacy->new( FILE => $testrc, DEFAULTS => { 'SCALAR 1' => 'foo', 'SCALAR 2' => 'bar', 'UNDEC' => 5, }, ); ok( $conf->read, 'read 2' ); ok( $conf->purge, 'purge 2'); @params = $conf->parameters; ok( scalar @params > 1, 'has parameters 3' ); ($p) = grep /^UNDEC$/, @params; ok( $p eq 'UNDEC', 'has default parameter' ); is( $conf->parameter( 'UNDEC' ), 5, 'default param value match' ); @params = $conf->parameters; ok( scalar @params == 3, 'has parameters 4' ); # end 05_purge.t Parse-PlainConfig-3.07/t/v2_02_property.t0000644000175000001440000000305612741127445017701 0ustar acorlissusers#!/usr/bin/perl -T # 02_property.t use Test::More tests => 34; use Paranoid; use Parse::PlainConfig::Legacy; use strict; use warnings; psecureEnv(); my $conf = new Parse::PlainConfig::Legacy; my %properties = ( PARAM_DELIM => '*', LIST_DELIM => ':', HASH_DELIM => '>', AUTOPURGE => 1, SMART_PARSER => 1, PADDING => 3, FILE => 'foo', MTIME => 3, ); my ($key, $value, %tmp); # Test setting bad properties/values ok( !eval '$conf->property( FOO => "bar" )', 'bad property 1'); ok( !$conf->property( PARAM_DELIM => [] ), 'bad property 2'); ok( !$conf->property( ORDER => "foo" ), 'bad property 3'); ok( !$conf->property( COERCE => [] ), 'bad property 4'); ok( !$conf->property( COERCE => { FOO => 'bar' } ), 'bad property 5'); # Test valid properties while ( ( $key, $value ) = each %properties ) { isnt( $conf->property( $key ), $value, "property $key default value" ); ok( $conf->property( $key => $value ), "property $key set"); is( $conf->property( $key ), $value, "property $key value $value"); } ok( $conf->property( ORDER => [ qw(FOO BAR ROO) ] ), 'property ORDER set'); ($key, $value) = @{ $conf->property( 'ORDER' ) }; is( $value, 'BAR', 'property ORDER get'); ok( $conf->property( COERCE => { FOO => 'list', BAR => 'string', ROO => 'hash', }), 'property COERCE set'); %tmp = %{ $conf->property( 'COERCE' ) }; is( $tmp{FOO}, 'list', 'property COERCE get'); ok( $conf->property( MAX_BYTES => 512 ), 'property MAX_BYTES set' ); # end 02_property.t Parse-PlainConfig-3.07/t/v3_09_mac.t0000644000175000001440000000236212741127445016564 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 15; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use CStyle; #PDEBUG = 20; my $obj = new CStyle; ok( defined $obj, 'new object - 1' ); ok( $obj->read('t/lib/mac.conf'), 'config read'); my $val = $obj->get('admin email'); is( $val, 'foo@bar.com', 'default scalar retrieval' ); my @val = $obj->get('hosts'); is( $val[0], 'host1.foo.com', 'default array retrieval' ); my %val = $obj->get('db'); is( $val{database}, 'mydb.db', 'default hash retrieval' ); $val = $obj->get('note'); ok( length $val, 'default hdoc retrieval' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval' ); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval' ); ok( $obj->set('nodefault', 'set'), 'set parameter'); $val = $obj->get('nodefault'); is( $val, 'set', 'get parameter' ); ok( $obj->set('loopback', $obj->get('localnet')), 'set prototype'); ($val) = $obj->get('loopback'); is( $val, '192.168.0.0/24', 'get prototype'); ok($obj->reset, 'reset config'); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval 2' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval 2' ); Parse-PlainConfig-3.07/t/v3_07_unix.t0000644000175000001440000000234712741127445017010 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 15; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use CStyle; my $obj = new CStyle; ok( defined $obj, 'new object - 1' ); ok( $obj->read('t/lib/unix.conf'), 'config read'); my $val = $obj->get('admin email'); is( $val, 'foo@bar.com', 'default scalar retrieval' ); my @val = $obj->get('hosts'); is( $val[0], 'host1.foo.com', 'default array retrieval' ); my %val = $obj->get('db'); is( $val{database}, 'mydb.db', 'default hash retrieval' ); $val = $obj->get('note'); ok( length $val, 'default hdoc retrieval' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval' ); $val = $obj->get('nodefault'); is( $val, 'whoops!', 'nodefault retrieval' ); ok( $obj->set('nodefault', 'set'), 'set parameter'); $val = $obj->get('nodefault'); is( $val, 'set', 'get parameter' ); ok( $obj->set('loopback', $obj->get('localnet')), 'set prototype'); ($val) = $obj->get('loopback'); is( $val, '192.168.0.0/24', 'get prototype'); ok($obj->reset, 'reset config'); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval 2' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval 2' ); Parse-PlainConfig-3.07/t/v3_04_bad_conf.t0000644000175000001440000000036512741127445017553 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 1; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use BadConf; my $obj = new BadConf; ok( !defined $obj, 'new object - 1' ); Parse-PlainConfig-3.07/t/v2_01_ini.t0000644000175000001440000000054412741127445016572 0ustar acorlissusers#!/usr/bin/perl -T # 01_ini.t use Test::More tests => 2; use Paranoid; use Parse::PlainConfig::Legacy; use strict; use warnings; psecureEnv(); my $conf; $conf = Parse::PlainConfig::Legacy->new( 'PARAM_DELIM' => '=', PADDING => 1 ); isnt( $conf, undef, 'constructor 3' ); isa_ok( $conf, 'Parse::PlainConfig::Legacy', 'constructor 4' ); # end 01_ini.t Parse-PlainConfig-3.07/t/v2_09_coerce.t0000644000175000001440000000223612741127445017263 0ustar acorlissusers# 09_coerce.t # # Tests coerce method use Parse::PlainConfig::Legacy; $|++; print "1..5\n"; my $test = 1; my $rcfile = './t/v2_testrc_smart'; my $conf = Parse::PlainConfig::Legacy->new( FILE => $rcfile, SMART_PARSER => 1, COERCE => { 'SCALAR 2' => 'string', 'LIST 3' => 'list', }, ); $conf->read; my %hash; # 1 scalar 2 $conf->parameter("SCALAR 2") eq '"these, are, all one => value"' ? print "ok $test\n" : print "not ok $test\n"; $test++; # 2 list 3 ($conf->parameter("LIST 3"))[2] eq "two => parts" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 3 coerce list 1 into string $conf->coerce('string', 'LIST 1'); $conf->parameter("LIST 1") eq "value1 , value2 , value3" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 4 .. 5 coerce scalar 2 into a hash $conf->parameter('SCALAR 2', ($conf->parameter('SCALAR 2') =~ /^"(.*)"$/)[0]); $conf->coerce('hash', 'SCALAR 2'); %hash = ( $conf->parameter('SCALAR 2') ); $hash{"these"} eq 'are' ? print "ok $test\n" : print "not ok $test\n"; $test++; $hash{"all one"} eq 'value' ? print "ok $test\n" : print "not ok $test\n"; $test++; # end 09_coerce.t Parse-PlainConfig-3.07/t/99_pod.t0000644000175000001440000000033312741127445016203 0ustar acorlissusers#!/usr/bin/perl -T use Paranoid; use Test::More; psecureEnv('/bin:/usr/bin:/usr/ccs/bin:/usr/local/bin'); eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Parse-PlainConfig-3.07/t/v2_12_purge.t0000644000175000001440000000161512741127445017137 0ustar acorlissusers# 12_purge.t # # Tests the purge and autopurge functionality use Parse::PlainConfig::Legacy; $|++; print "1..5\n"; my $test = 1; my $conf = new Parse::PlainConfig::Legacy; my $testrc = "./t/v2_testrc"; my ($val, $val2, @params); $conf->read($testrc); # 1 & 2 Test purge @params = $conf->parameters(); @params ? print "ok $test\n" : print "not ok $test\n"; $test++; $conf->purge(); @params = $conf->parameters(); @params ? print "not ok $test\n" : print "ok $test\n"; $test++; # 3 .. 5 Test autopurge $conf->read; $conf->parameter("FOO" => "BAR"); @params = $conf->parameters(); grep(/^FOO$/, @params) ? print "ok $test\n" : print "not ok $test\n"; $test++; $conf->property("AUTOPURGE" => 1); $conf->read; @params = $conf->parameters(); grep(/^FOO$/, @params) ? print "not ok $test\n" : print "ok $test\n"; $test++; @params ? print "ok $test\n" : print "not ok $test\n"; $test++; # end 12_purge.t Parse-PlainConfig-3.07/t/v3_10_subclass-init.t0000644000175000001440000000047214503722177020575 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 2; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use MyConf2; #PDEBUG = 20; my $obj = new MyConf2; ok( defined $obj, 'new object - 1' ); ok( length $obj->default, 'conf default - 1' ); Parse-PlainConfig-3.07/t/v2_testrc0000644000175000001440000000205212741127445016551 0ustar acorlissusers# Scalar tests SCALAR 1: value1 SCALAR 2: "these, are, all one => value" SCALAR 3: this is a \ continued line. SCALAR 4: ASDFKAS234123098ASDFA9082341\ ASDFIO23489078907SFASDF8A972 SCALAR 5: this is a really long text that should definitely cause the output \ generator to wrap lines -- hopefully breaking along whitespace. \ I should also generation a really freaking long line just to see \ it break on non-whitespace as well. Well, how about this: \ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\ CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\ DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD # List tests LIST 1: value1, value2, value3 LIST 2: value1, "two, parts", value3, "\"two => parts\"" LIST 3: value1, "two, parts", "two => parts" # Hash tests HASH 1: one => 1, two => 2, three => "Three for Me! 3 => 2", \ four => 4 # Disconnected comment # # Empty EMPTY: Parse-PlainConfig-3.07/t/v2_06_scalar.t0000644000175000001440000000512212741127445017262 0ustar acorlissusers# 06_scalar.t # # Tests for proper extraction of scalar values use Parse::PlainConfig::Legacy; $|++; print "1..13\n"; my $test = 1; my $rcfile = './t/v2_testrc'; my $conf = Parse::PlainConfig::Legacy->new(FILE => $rcfile); # First series with smart parser off # # 1 scalar 1 $conf->read($rcfile); $conf->parameter("SCALAR 1") eq "value1" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 2 scalar 2 $conf->parameter("SCALAR 2") eq "these, are, all one => value" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 3 scalar 3 $conf->parameter("SCALAR 3") eq "this is a continued line." ? print "ok $test\n" : print "not ok $test\n"; $test++; # 4 scalar 4 $conf->parameter("SCALAR 4") eq "ASDFKAS234123098ASDFA9082341ASDFIO23489078907SFASDF8A972" ? print "ok $test\n" : print "not ok $test\n"; $test++; # Second series with smart parser on # # 5 scalar 1 $conf->property(SMART_PARSER => 1); $conf->property(AUTOPURGE => 1); $conf->read("${rcfile}_smart"); $conf->parameter("SCALAR 1") eq "value1" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 6 scalar 2 $conf->parameter("SCALAR 2") eq "these, are, all one => value" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 7 scalar 3 $conf->parameter("SCALAR 3") eq "this is a continued line." ? print "ok $test\n" : print "not ok $test\n"; $test++; # 8 scalar 4 $conf->parameter("SCALAR 4") eq "ASDFKAS234123098ASDFA9082341ASDFIO23489078907SFASDF8A972" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 9 scalar 2 with scalar coercion set and smart parsing $conf->coerce("string", "SCALAR 2"); $conf->read; $conf->parameter("SCALAR 2") eq '"these, are, all one => value"' ? print "ok $test\n" : print "not ok $test\n"; $test++; # Set tests # # 10 new scalar 1 $conf->parameter("NEW SCALAR 1", "this is new"); $conf->parameter("NEW SCALAR 1") eq "this is new" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 11 new scalar 2 with coercion set $conf->coerce("string", "NEW SCALAR 2"); $conf->parameter("NEW SCALAR 2", "this is also new"); $conf->parameter("NEW SCALAR 2") eq "this is also new" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 12 new scalar 2 with list value $conf->parameter("NEW SCALAR 2", [qw(this is new again)]); $conf->parameter("NEW SCALAR 2") eq "this , is , new , again" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 13 new scalar 2 with hash value $conf->parameter("NEW SCALAR 2", {qw(this is new indeed)}); $conf->parameter("NEW SCALAR 2") eq "new => indeed , this => is" ? print "ok $test\n" : print "not ok $test\n"; $test++; # end 06_scalar.t Parse-PlainConfig-3.07/t/v2_10_write.t0000644000175000001440000000312112741127445017137 0ustar acorlissusers# 10_write.t # # Tests the write method use Parse::PlainConfig::Legacy; $|++; print "1..6\n"; my $test = 1; my $conf = new Parse::PlainConfig::Legacy; my $nconf = new Parse::PlainConfig::Legacy; my $testrc = "./t/v2_testrc"; $conf->coerce('string', 'SCALAR 5'); $conf->read($testrc); # 1 write w/o smart $rv = $conf->write("${testrc}_write"); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # 2 verify worthiness of new file $rv = $nconf->read("${testrc}_write"); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # 3 compare values in both $conf->parameter('SCALAR 5') eq $nconf->parameter('SCALAR 5') ? print "ok $test\n" : print "not ok $test\n"; unlink "${testrc}_write"; $test++; # 4 write w/smart $conf->property("SMART_PARSER", 1); $conf->coerce('string', 'SCALAR 1', 'SCALAR 2', 'SCALAR 3', 'SCALAR 4', 'SCALAR 5'); $conf->coerce('list', 'LIST 1', 'LIST 2', 'LIST 3'); $conf->coerce('hash', 'HASH 1'); $rv = $conf->write("${testrc}_write_smart"); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # 5 verify worthiness of new file $nconf->purge; $nconf->property("SMART_PARSER", 1); $nconf->coerce('string', 'SCALAR 1', 'SCALAR 2', 'SCALAR 3', 'SCALAR 4', 'SCALAR 5'); $nconf->coerce('list', 'LIST 1', 'LIST 2', 'LIST 3'); $nconf->coerce('hash', 'HASH 1'); $nconf->read("${testrc}_write_smart"); $rv ? print "ok $test\n" : print "not ok $test\n"; $test++; # 6 compare values in both $conf->parameter('SCALAR 5') eq $nconf->parameter('SCALAR 5') ? print "ok $test\n" : print "not ok $test\n"; unlink "${testrc}_write_smart"; $test++; # end 10_write.t Parse-PlainConfig-3.07/t/v3_08_msdos.t0000644000175000001440000000236412741127445017152 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 15; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use CStyle; #PDEBUG = 20; my $obj = new CStyle; ok( defined $obj, 'new object - 1' ); ok( $obj->read('t/lib/msdos.conf'), 'config read'); my $val = $obj->get('admin email'); is( $val, 'foo@bar.com', 'default scalar retrieval' ); my @val = $obj->get('hosts'); is( $val[0], 'host1.foo.com', 'default array retrieval' ); my %val = $obj->get('db'); is( $val{database}, 'mydb.db', 'default hash retrieval' ); $val = $obj->get('note'); ok( length $val, 'default hdoc retrieval' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval' ); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval' ); ok( $obj->set('nodefault', 'set'), 'set parameter'); $val = $obj->get('nodefault'); is( $val, 'set', 'get parameter' ); ok( $obj->set('loopback', $obj->get('localnet')), 'set prototype'); ($val) = $obj->get('loopback'); is( $val, '192.168.0.0/24', 'get prototype'); ok($obj->reset, 'reset config'); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval 2' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval 2' ); Parse-PlainConfig-3.07/t/v3_05_no_defaults.t0000644000175000001440000000217412741127445020324 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 14; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use NoDefaults; #PDEBUG = 20; my $obj = new NoDefaults; ok( defined $obj, 'new object - 1' ); my $val = $obj->get('admin email'); is( $val, undef, 'default scalar retrieval' ); my @val = $obj->get('hosts'); is( $val[0], undef, 'default array retrieval' ); my %val = $obj->get('db'); is( $val{database}, undef, 'default hash retrieval' ); $val = $obj->get('note'); ok( !length $val, 'default hdoc retrieval' ); ($val) = $obj->get('loopback'); is( $val, undef, 'default proto retrieval' ); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval' ); ok( $obj->set('nodefault', 'set'), 'set parameter'); $val = $obj->get('nodefault'); is( $val, 'set', 'get parameter' ); ok($obj->reset, 'reset config'); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval 2' ); #PDEBUG = 9; ok(! $obj->parse('gack! Spurious text!!!'), 'spurious text 1'); ok(! $obj->set('admin user', 'foo'), 'invalid prop 1'); ok(! $obj->get('admin user'), 'invalid prop 2'); Parse-PlainConfig-3.07/t/v2_08_hash.t0000644000175000001440000000247412741127445016751 0ustar acorlissusers# 08_hash.t # # Tests for proper extraction of hash values use Parse::PlainConfig::Legacy; $|++; print "1..6\n"; my $test = 1; my $rcfile = './t/v2_testrc'; my $conf = Parse::PlainConfig::Legacy->new(FILE => $rcfile); $conf->read($rcfile); my %hash = ( $conf->parameter("HASH 1") ); # 1 hash 1 $hash{two} eq "2" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 2 hash 1 $hash{three} eq "Three for Me! 3 => 2" ? print "ok $test\n" : print "not ok $test\n"; $test++; # Set tests # # 3 new hash 1 $conf->parameter('NEW HASH 1', { 'foo' => 'bar' }); %hash = $conf->parameter('NEW HASH 1'); $hash{foo} eq "bar" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 4 new hash 2 with coercion set $conf->coerce('hash', 'NEW HASH 2'); $conf->parameter('NEW HASH 2', { 'foo' => 'bar' }); %hash = $conf->parameter('NEW HASH 2'); $hash{foo} eq "bar" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 5 new hash 2 with string value $conf->parameter('NEW HASH 2', "bar => foo"); %hash = $conf->parameter('NEW HASH 2'); $hash{bar} eq "foo" ? print "ok $test\n" : print "not ok $test\n"; $test++; # 6 new hash 2 with list value $conf->parameter('NEW HASH 2', [qw(foo bar roo)]); %hash = $conf->parameter('NEW HASH 2'); $hash{foo} eq "bar" ? print "ok $test\n" : print "not ok $test\n"; $test++; # end 08_hash.t Parse-PlainConfig-3.07/t/v3_03_parameters.t0000644000175000001440000000376214540710100020147 0ustar acorlissusers#!/usr/bin/perl -T use Test::More tests => 25; use Paranoid; use Paranoid::Debug; use Parse::PlainConfig; use strict; use warnings; psecureEnv(); use lib qw(t/lib); use MyConf; #PDEBUG = 20; my $obj = new MyConf; ok( defined $obj, 'new object - 1' ); my $val = $obj->get('admin email'); is( $val, 'root@localhost', 'default scalar retrieval' ); my @val = $obj->get('hosts'); is( $val[0], 'localhost', 'default array retrieval' ); my %val = $obj->get('db'); is( $val{database}, 'sample.db', 'default hash retrieval' ); $val = $obj->get('note'); ok( length $val, 'default hdoc retrieval' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval' ); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval' ); ok( $obj->set( 'nodefault', 'set' ), 'set parameter' ); $val = $obj->get('nodefault'); is( $val, 'set', 'get parameter' ); ok( $obj->set( 'loopback', $obj->get('localnet') ), 'set prototype' ); ($val) = $obj->get('loopback'); is( $val, '192.168.0.0/24', 'get prototype' ); $val = [ $obj->prototyped ]; is( scalar @$val, 3, 'prototyped all 1' ); ok( ( scalar grep { $_ eq 'loopback' } @$val ), 'prototyped all 2' ); $val = [ $obj->prototyped('declare acl') ]; is( scalar @$val, 2, 'prototyped specific 1' ); ok( ( scalar grep { $_ eq 'loopback' } @$val ), 'prototyped specific 2' ); $val = [ $obj->prototyped('declare foo') ]; is( scalar @$val, 1, 'prototyped specific 3' ); ok( ( scalar grep { $_ eq 'bar' } @$val ), 'prototyped specific 4' ); ok( $obj->reset, 'reset config' ); $val = $obj->get('nodefault'); ok( !defined $val, 'nodefault retrieval 2' ); ($val) = $obj->get('loopback'); is( $val, '127.0.0.1', 'default proto retrieval 2' ); #PDEBUG = 9; ok( !$obj->parse('gack! Spurious text!!!'), 'spurious text 1' ); ok( !$obj->parse('declare acl db foo'), 'proto/prop conflict 1' ); ok( !$obj->parse('declare foo localnet bar'), 'proto/prop conflict 2' ); ok( !$obj->set( 'admin user', 'foo' ), 'invalid prop 1' ); ok( !$obj->get('admin user'), 'invalid prop 2' ); Parse-PlainConfig-3.07/MANIFEST0000644000175000001440000000202314547616507015607 0ustar acorlissusersMakefile.PL INSTALL MANIFEST LICENSE CHANGELOG README lib/Parse/PlainConfig.pm lib/Parse/PlainConfig/Constants.pm lib/Parse/PlainConfig/Legacy.pm lib/Parse/PlainConfig/Settings.pm t/lib/01_include_me.conf t/lib/BadConf.pm t/lib/CStyle.pm t/lib/MyConf.pm t/lib/NoDefaults.pm t/lib/mac.conf t/lib/msdos.conf t/lib/unix.conf t/lib/MyConf2.pm t/98_pod_coverage.t t/99_pod.t t/v2_01_ini.t t/v2_02_property.t t/v2_03_read.t t/v2_04_parameters.t t/v2_05_purge.t t/v2_06_scalar.t t/v2_07_list.t t/v2_08_hash.t t/v2_09_coerce.t t/v2_10_write.t t/v2_11_order.t t/v2_12_purge.t t/v2_13_readIfNewer.t t/v2_15_defaults.t t/v2_16_hasParameter.t t/v2_testrc t/v2_testrc_smart t/v3_01_constants.t t/v3_02_init.t t/v3_03_parameters.t t/v3_04_bad_conf.t t/v3_05_no_defaults.t t/v3_06_c_style.t t/v3_07_unix.t t/v3_08_msdos.t t/v3_09_mac.t t/v3_10_subclass-init.t t/v3_11_subclass-parameters.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Parse-PlainConfig-3.07/CHANGELOG0000644000175000001440000000436614547616463015705 0ustar acorlissusersCHANGELOG v3.07 (2024/01/10) ------------------ --Fixed return value of the get method where it comes to prototyped parameters. The problem was only seen for array/hash types that had no contents. v3.06 (2023/09/23) ------------------ --Typos in documentation (Debian Perl Group) --Made PPC class subclassable, allowing for inherited parameters and prototypes --Adjusted debug output for Paranoid::Debug v2.10 v3.05 (2017/03/23) ------------------ --Forgot to update minimum version for Class::EHierarchy in Makefile.PL v3.04 (2017/03/23) ------------------ --Rewrite to adapt to new Class::EHierarchy API v3.03 (2016/08/09) ------------------ --Minor bug fixed in which an error found by the parser is reset by any any good blocks afterwards --Typos in documentation (found by Debian Perl Group) v3.02 (2016/05/26) ------------------ --Improved Makefile.PL to better report on requirements --Removed Carp dependency --Added error method to store last error string --Added prototyped method to retrieve all or specific prototyped properties v3.00 (2016/05/10) ------------------ --Complete rewrite targetted towards ease-of-use for developers --Parsing objects are now subclasses --Added new here document capability --Simplified API --I/O handled by latest Paranoid::IO release --Internal class logic managed by Class::EHierarchy v2.06 (2008/07/07) ------------------ --write method was always reporting true when it's possible that it could fail for various reasons. Fixed to reflect actual result --write method now detaints filename before calling open v2.05 (2008/04/29) ------------------ --Updated debug messages since Paranoid now adds calling function v2.02 (2006/07/25) ------------------ --Fixed AUTOPURGE (didn't work since it was looking for old key PURGE) --Added new method readIfNewer v2.01 (2006/07/21) ------------------ --Forgot to implement documented MAX_BYTES. Fixed. --Wasn't saving all errors to Parse::PlainConfig::ERROR as documented. Fixed. v2.0 (2006/05/26) ----------------- --Complete rewrite --Built against Paraniod::* modules --Internal diagnostics provided via Paraniod::Debug --Smart parser mode added --Forced coercion now available for all datatypes (strings, lists, hashes) --Lists and hash delimiters can now be user-defined Parse-PlainConfig-3.07/lib/0000750000175000001440000000000014547616507015222 5ustar acorlissusersParse-PlainConfig-3.07/lib/Parse/0000750000175000001440000000000014547616507016274 5ustar acorlissusersParse-PlainConfig-3.07/lib/Parse/PlainConfig/0000750000175000001440000000000014547616507020465 5ustar acorlissusersParse-PlainConfig-3.07/lib/Parse/PlainConfig/Settings.pm0000644000175000001440000001256514547615346022641 0ustar acorlissusers# Parse::PlainConfig::Settings -- Settings Class # # (c) 2016, Arthur Corliss # # $Id: lib/Parse/PlainConfig/Settings.pm, 3.07 2024/01/10 13:32:06 acorliss Exp $ # # This software is licensed under the same terms as Perl, itself. # Please see http://dev.perl.org/licenses/ for more information. # ##################################################################### ##################################################################### # # Environment definitions # ##################################################################### package Parse::PlainConfig::Settings; use 5.008; use strict; use warnings; use vars qw($VERSION); ($VERSION) = ( q$Revision: 3.07 $ =~ /(\d+(?:\.\d+)+)/sm ); use Paranoid; use Paranoid::Debug; use Parse::PlainConfig::Constants qw(:all); use Class::EHierarchy qw(:all); use vars qw(@ISA @_properties @_methods); @ISA = qw(Class::EHierarchy); @_properties = ( [ CEH_PUB | CEH_SCALAR, 'tab stop', DEFAULT_TAB ], [ CEH_PUB | CEH_SCALAR, 'subindentation', DEFAULT_SUBI ], [ CEH_PUB | CEH_SCALAR, 'comment', DEFAULT_CMMT ], [ CEH_PUB | CEH_SCALAR, 'delimiter', DEFAULT_PDLM ], [ CEH_PUB | CEH_SCALAR, 'list delimiter', DEFAULT_LDLM ], [ CEH_PUB | CEH_SCALAR, 'hash delimiter', DEFAULT_HDLM ], [ CEH_PUB | CEH_SCALAR, 'here doc', DEFAULT_HDOC ], [ CEH_PUB | CEH_HASH, 'property types' ], [ CEH_PUB | CEH_HASH, 'property regexes' ], [ CEH_PUB | CEH_HASH, 'prototypes' ], [ CEH_PUB | CEH_HASH, 'prototype regexes' ], [ CEH_PUB | CEH_HASH, 'prototype registry' ], [ CEH_PUB | CEH_SCALAR, 'error' ], [ CEH_PUB | CEH_ARRAY, '_ppcClasses' ], ); ##################################################################### # # Module code follows # ##################################################################### sub tabStop { my $obj = shift; return $obj->get('tab stop'); } sub subindentation { my $obj = shift; return $obj->get('subindentation'); } sub comment { my $obj = shift; return $obj->get('comment'); } sub delimiter { my $obj = shift; return $obj->get('delimiter'); } sub listDelimiter { my $obj = shift; return $obj->get('list delimiter'); } sub hashDelimiter { my $obj = shift; return $obj->get('hash delimiter'); } sub hereDoc { my $obj = shift; return $obj->get('here doc'); } sub propertyTypes { my $obj = shift; return $obj->get('property types'); } sub propertyRegexes { my $obj = shift; return $obj->get('property regexes'); } sub prototypes { my $obj = shift; return $obj->get('prototypes'); } sub prototypeRegexes { my $obj = shift; return $obj->get('prototype regexes'); } 1; __END__ =head1 NAME Parse::PlainConfig::Settings - Settings Class =head1 VERSION $Id: lib/Parse/PlainConfig/Settings.pm, 3.07 2024/01/10 13:32:06 acorliss Exp $ =head1 SYNOPSIS use Parse::PlainConfig::Settings; my $settings = new Parse::PlainConfig::Settings; $ts = $settings->tabStop; $subindent = $settings->subindentation; $comment = $settings->comment; $delim = $settings->delimiter; $ldelim = $settings->listDelimiter; $hdelim = $settings->hashDelimiter; $hdoc = $settings->hereDoc; %propTypes = $settings->propertyTypes; %propRegex = $settings->propertyRegexes; %prototypes = $settings->prototypes; %protoRegex = $settings->prototypeRegexes; =head1 DESCRIPTION The settings object is created and initialized automatically by L. =head1 SUBROUTINES/METHODS =head2 tabStop $ts = $settings->tabStop; Default column width for tab stops. =head2 subindentation $subindent = $settings->subindentation; Default columns for indentation on line continuations. =head2 comment $comment = $settings->comment; Default character sequence for comments. =head2 delimiter $delim = $settings->delimiter; Default character sequence used as the delimiter between the parameter name and the parameter value. =head2 listDelimiter $ldelim = $settings->listDelimiter; Default character sequence used as the delimiter between array elements. =head2 hashDelimiter $hdelim = $settings->hashDelimiter; Default character sequence used as the delimiter between key/value pairs. =head2 hereDoc $hdoc = $settings->hereDoc; Default character sequence used as the token marking the end of here docs. =head2 propertyTypes %propTypes = $settings->propertyTypes; Hash of property names => data types. =head2 propertyRegexes %propRegex = $settings->propertyRegexes; Hash of property names to regular expression to extract data from the line. =head2 prototypes %prototypes = $settings->prototypes; Hash of prototype names => data types. =head2 prototypeRegexes %protoRegex = $settings->prototypeRegexes; Hash of prototype names to regular expression to extract data from the line. =head1 DEPENDENCIES =over =item o L =item o L =item o L =item o L =back =head1 BUGS AND LIMITATIONS =head1 AUTHOR Arthur Corliss (corliss@digitalmages.com) =head1 LICENSE AND COPYRIGHT This software is licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information. (c) 2016, Arthur Corliss (corliss@digitalmages.com) Parse-PlainConfig-3.07/lib/Parse/PlainConfig/Legacy.pm0000644000175000001440000014077514547615346022252 0ustar acorlissusers# Parse::PlainConfig::Legacy -- Parsing Engine Legacy for Parse::PlainConfig # # (c) 2002 - 2023, Arthur Corliss , # # $Id: lib/Parse/PlainConfig/Legacy.pm, 3.07 2024/01/10 13:32:06 acorliss Exp $ # # This software is licensed under the same terms as Perl, itself. # Please see http://dev.perl.org/licenses/ for more information. # ##################################################################### ##################################################################### # # Environment definitions # ##################################################################### package Parse::PlainConfig::Legacy; use 5.006; use strict; use warnings; use vars qw($VERSION); ($VERSION) = ( q$Revision: 3.07 $ =~ /(\d+(?:\.(\d+))+)/sm ); use Parse::PlainConfig::Constants qw(:all); use Text::ParseWords; use Text::Tabs; use Carp; use Fcntl qw(:flock); use Paranoid; use Paranoid::Data; use Paranoid::Debug; use Paranoid::Filesystem; use Paranoid::Input; use Paranoid::IO qw(:all); use Paranoid::IO::Line; ##################################################################### # # Module code follows # ##################################################################### { my $ERROR = ''; sub ERROR : lvalue { $ERROR; } } sub new { # Purpose: Creates a new object # Returns: Object reference if successful, undef if not # Usage: $obj = Parse::PlainConfig->new(%PARAMS); my $class = shift; my $self = { CONF => {}, ORDER => [], FILE => undef, PARAM_DELIM => ':', LIST_DELIM => ',', HASH_DELIM => '=>', AUTOPURGE => 0, COERCE => {}, DEFAULTS => {}, SMART_PARSER => 0, PADDING => 2, MAX_BYTES => PPC_DEF_SIZE, MTIME => 0, }; my %args = @_; my ( $k, $v, $rv ); subPreamble( PPCDLEVEL1, '$%', $class, %args ); bless $self, $class; # Assign all the arguments $rv = 1; while ( $rv && scalar keys %args ) { $k = shift @{ [ keys %args ] }; $v = $args{$k}; delete $args{$k}; $rv = 0 unless $self->property( $k, $v ); } $self = undef unless $rv; subPostamble( PPCDLEVEL1, '$', $self ); return $self; } sub property { # Purpose: Gets/sets object property value # Returns: Value of property in Get mode, true/false in set mode # Usage: $value = $obj->property($name); # Usage: $rv = $obj->property($name, $value); my $self = shift; my @args = @_; my $arg = $_[0]; my $val = $_[1]; my $ival = defined $val ? $val : 'undef'; my $rv = 1; my ( $k, $v ); croak 'Mandatory first argument must be a valid property name' unless defined $arg and exists $$self{$arg}; subPreamble( PPCDLEVEL1, '$$', $arg, $val ); pdebug( 'method is in ' . ( scalar @args == 2 ? 'set' : 'get' ) . ' mode', PPCDLEVEL1 ); $arg = uc $arg; # Validate arguments & value if ( scalar @args == 2 ) { if ( $arg eq 'ORDER' ) { # ORDER must be a list reference unless ( ref $val eq 'ARRAY' ) { $rv = 0; Parse::PlainConfig::Legacy::ERROR = pdebug( '%s\'s value must be a list reference', PPCDLEVEL1, $arg ); } } elsif ( $arg eq 'CONF' or $arg eq 'COERCE' or $arg eq 'DEFAULTS' ) { # CONF, COERCE, and DEFAULTS must be a hash reference unless ( ref $val eq 'HASH' ) { $rv = 0; Parse::PlainConfig::Legacy::ERROR = pdebug( '%s\'s value must be a hash reference', PPCDLEVEL1, $arg ); } if ($rv) { if ( $arg eq 'COERCE' ) { # Validate each key/value pair in COERCE foreach ( keys %$val ) { $ival = defined $$val{$_} ? $$val{$_} : 'undef'; unless ( $ival eq 'string' or $ival eq 'list' or $ival eq 'hash' ) { Parse::PlainConfig::Legacy::ERROR = pdebug( 'coerced data type (%s: %s) not a string, list, or hash', PPCDLEVEL1, $_, $ival ); $rv = 0; } } } elsif ( $arg eq 'DEFAULTS' ) { # Copy over the defaults into CONF (not overriding # existing values) while ( ( $k, $v ) = each %{ $$self{DEFAULTS} } ) { $$self{CONF}{$k} = { 'Value' => $v } unless exists $$self{CONF}{$k}; } } } # TODO: Validate properties like PADDING that have a concrete # TODO: list of valid values? } elsif ( ref $val ne '' ) { # Everything else should be a scalar value $rv = 0; Parse::PlainConfig::Legacy::ERROR = pdebug( '%s\'s value must be a scalar value', PPCDLEVEL1, $arg ); } } # Set the value if all's kosher if ($rv) { if ( scalar @args == 2 ) { # Assign the value if ( ref $val eq 'ARRAY' ) { # Copy array contents in $$self{$arg} = [@$val]; } elsif ( ref $val eq 'HASH' ) { # Copy hash contents in $$self{$arg} = {%$val}; } else { # Assign the scalar value $$self{$arg} = $val; } } else { # Copy the value if ( defined $$self{$arg} and ref $$self{$arg} ne '' ) { $rv = ref $$self{$arg} eq 'ARRAY' ? [] : ref $$self{$arg} eq 'HASH' ? {} : undef; if ( defined $rv ) { unless ( deepCopy( $$self{$arg}, $rv ) ) { Parse::PlainConfig::Legacy::ERROR = pdebug( 'failed to copy data from %s: %s', PPCDLEVEL1, Paranoid::ERROR, $arg ); } } else { Parse::PlainConfig::Legacy::ERROR = pdebug( 'I don\'t know how to copy %s (%s)', PPCDLEVEL1, $$self{$arg}, $arg ); } } else { $rv = $$self{$arg}; } } } subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } sub purge { # Purpose: Performs a manual purge of internal data # Returns: True # Usage: $obj->purge; my $self = shift; my ( $k, $v ); subPreamble( PPCDLEVEL1, '$', $self ); # First, purge all existing values delete @{ $$self{CONF} }{ keys %{ $$self{CONF} } }; # Second, apply default values while ( ( $k, $v ) = each %{ $$self{DEFAULTS} } ) { $$self{CONF}{$k} = { 'Value' => $v }; } subPostamble( PPCDLEVEL1, '$', 1 ); return 1; } sub read { # Purpose: Reads either the passed filename or an internally recorded one # Returns: True or false depending on success of read & parse # Usage: $rv = $obj->read; # Usage: $rv = $obj->read($filename); my $self = shift; my $file = shift || $$self{FILE}; my $rv = 0; my $oldSize = PIOMAXFSIZE; my ( $line, @lines ); croak 'Optional first argument must be a defined filename or the FILE ' . 'property must be set' unless defined $file; subPreamble( PPCDLEVEL1, '$$', $self, $file ); # Reset the error string and update the internal filename Parse::PlainConfig::Legacy::ERROR = ''; $$self{FILE} = $file; # Temporarily set the specified size limit PIOMAXFSIZE = $$self{MAX_BYTES}; # Store the file's current mtime $$self{MTIME} = ( stat $file )[MTIME]; if ( detaint( $file, 'filename' ) ) { if ( slurp( $file, @lines, 1 ) ) { # Empty the current config hash and key order $self->purge if $$self{AUTOPURGE}; # Parse the rc file's lines $rv = $self->_parse(@lines); } else { Parse::PlainConfig::Legacy::ERROR = pdebug( Paranoid::ERROR, PPCDLEVEL1 ); } } else { Parse::PlainConfig::Legacy::ERROR = pdebug( 'Filename failed detaint check', PPCDLEVEL1 ); } # Restore old size limit PIOMAXFSIZE = $oldSize; subPostamble( PPCDLEVEL1, '$', $rv ); # Return the result code return $rv; } sub readIfNewer ($) { # Purpose: Performs a file read/parse if the file is newer than last read # Returns: 1 if read/parse was successful, 2 if file is the same age, 0 # on any errors # Usage: $rv = $obj->readIfNewer; my $self = shift; my $file = $$self{FILE}; my $omtime = $$self{MTIME}; my $rv = 0; my $mtime; croak 'The FILE property must be set' unless defined $file; subPreamble( PPCDLEVEL1, '$', $self ); # Try to read the file if ( -e $file && -r _ ) { # File exists and appears to be readable, get the mtime $mtime = ( stat _ )[MTIME]; pdebug( 'current mtime: %s last: %s', PPCDLEVEL2, $mtime, $omtime ); # Read the file if it's newer, or return 2 $rv = $mtime > $omtime ? $self->read : 2; } else { # Report errors Parse::PlainConfig::Legacy::ERROR = pdebug( 'file (%s) does not exist or is not readable', PPCDLEVEL1, $file ); } subPostamble( PPCDLEVEL1, '$', $rv ); # Return the result code return $rv; } sub write { # Purpose: Writes the file to disk # Returns: True/False depending on success of write # Usage: $rv = $obj->write; # Usage: $rv = $obj->write($filename); my $self = shift; my $file = shift || $$self{FILE}; my $padding = shift; my $conf = $$self{CONF}; my $order = $$self{ORDER}; my $coerce = $$self{COERCE}; my $smart = $$self{SMART_PARSER}; my $paramDelim = $$self{PARAM_DELIM}; my $hashDelim = $$self{HASH_DELIM}; my $listDelim = $$self{LIST_DELIM}; my $rv = 0; my $tw = DEFAULT_TW; my $delimRegex = qr/(?:\Q$hashDelim\E|\Q$listDelim\E)/sm; my ( @forder, $type, $param, $value, $description, $entry, $out ); my ( $tmp, $tvalue, $lines, $fh ); # TODO: Implement non-blocking flock support # TODO: Store read padding and/or use PADDING property value croak 'Optional first argument must be a defined filename or the FILE ' . 'property must be set' unless defined $file; $padding = 2 unless defined $padding; $tw -= 2 unless $smart; subPreamble( PPCDLEVEL1, '$$$', $self, $file, $padding ); # Pad the delimiter as specified $paramDelim = $padding == 0 ? $paramDelim : $padding == 1 ? " $paramDelim" : $padding == 2 ? "$paramDelim " : " $paramDelim "; pdebug( 'PARAM_DELIM w/padding is \'%s\'', PPCDLEVEL2, $paramDelim ); # Create a list of parameters for output @forder = @$order; foreach $tmp ( sort keys %$conf ) { push @forder, $tmp unless grep /^\Q$tmp\E$/sm, @forder; } pdebug( "order of params to be written:\n\t%s", PPCDLEVEL2, @forder ); # Compose the new output $out = ''; foreach $param (@forder) { # Determine the datatype $value = exists $$conf{$param} ? $$conf{$param}{Value} : ''; $description = exists $$conf{$param} ? $$conf{$param}{Description} : ''; $type = exists $$coerce{$param} ? $$coerce{$param} : ref $value eq 'HASH' ? 'hash' : ref $value eq 'ARRAY' ? 'list' : 'string'; pdebug( 'adding %s param (%s)', PPCDLEVEL2, $type, $param ); # Append the comments $out .= $description; $out .= "\n" unless $out =~ /\n$/sm; # Start the new entry with the parameter name and delimiter $entry = "$param$paramDelim"; # Append the value, taking into consideration the smart parser # and coercion settings if ( $type eq 'string' ) { # String type $tvalue = $value; unless ( $smart && exists $$coerce{$param} ) { $tvalue =~ s/"/\\"/smg; $tvalue = "\"$tvalue\"" if $tvalue =~ /$delimRegex/sm; } $lines = "$entry$tvalue"; } elsif ( $type eq 'list' ) { # List type $tvalue = [@$value]; foreach (@$tvalue) { s/"/\\"/smg; if ( $smart && exists $$coerce{$param} ) { $_ = "\"$_\"" if /\Q$listDelim\E/sm; } else { $_ = "\"$_\"" if /$delimRegex/sm; } } $lines = $entry . join " $listDelim ", @$tvalue; } else { # Hash type $tvalue = {%$value}; foreach ( keys %$tvalue ) { $tmp = $_; $tmp =~ s/"/\\"/smg; $tmp = "\"$tmp\"" if /$delimRegex/sm; if ( $tmp ne $_ ) { $$tvalue{$tmp} = $$tvalue{$_}; delete $$tvalue{$_}; } $$tvalue{$tmp} =~ s/"/\\"/smg; $$tvalue{$tmp} = "\"$$tvalue{$tmp}\"" if $$tvalue{$tmp} =~ /$delimRegex/sm; } $lines = $entry . join " $listDelim ", map {"$_ $hashDelim $$tvalue{$_}"} sort keys %$tvalue; } # wrap the output to the column width and append to the output $out .= _wrap( '', "\t", $tw, ( $smart ? "\n" : "\\\n" ), $lines ); $out .= "\n" unless $out =~ /\n$/sm; } # Write the file if ( detaint( $file, 'filename' ) ) { if ( open $fh, '>', $file ) { # Write the file flock $fh, LOCK_EX; if ( print $fh $out ) { $rv = 1; } else { Parse::PlainConfig::Legacy::ERROR = $!; } flock $fh, LOCK_UN; close $fh; # Store the new mtime on successful writes $$self{MTIME} = ( stat $file )[MTIME] if $rv; } else { # Report the errors Parse::PlainConfig::Legacy::ERROR = pdebug( 'error writing file: %s', PPCDLEVEL1, $! ); } } else { # Detainting filename failed Parse::PlainConfig::Legacy::ERROR = pdebug( 'illegal characters in filename: %s', PPCDLEVEL1, $file ); } subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } sub parameters { # Purpose: Returns a list of all parsed parameters # Returns: List of parameter names with configure values # Usage: @params = $obj->parameters; my $self = shift; my @parameters = keys %{ $$self{CONF} }; pdebug( 'called method -- rv: %s', PPCDLEVEL1, @parameters ); return @parameters; } sub parameter { # Purpose: Gets/sets named parameter # Returns: True/false in set mode, Parameter value in get mode # Usage: $rv = $obj->parameter($name); # Usage: $rv = $obj->parameter($name, $value); my $self = shift; my @args = @_; my $param = $args[0]; my $value = $args[1]; my $ivalue = defined $value ? $value : 'undef'; my $conf = $$self{CONF}; my $listDelim = $$self{LIST_DELIM}; my $hashDelim = $$self{HASH_DELIM}; my $paramDelim = $$self{PARAM_DELIM}; my $coerceType = exists $$self{COERCE}{$param} ? $$self{COERCE}{$param} : 'undef'; my $defaults = $$self{DEFAULTS}; my $rv = 1; my $delimRegex = qr/(?:\Q$hashDelim\E|\Q$listDelim\E)/sm; my ( $finalValue, @elements ); # TODO: Consider storing a list/hash padding value as well, for use # TODO: in coercion to string. croak 'Mandatory firest argument must be a defined parameter name' unless defined $param; subPreamble( PPCDLEVEL1, '$$$', $self, $param, $ivalue ); if ( scalar @args == 2 ) { pdebug( 'method in set mode', PPCDLEVEL1 ); # Create a blank record if it hasn't been defined yet $$conf{$param} = { Value => '', Description => '', } unless exists $$conf{$param}; # Start processing value assignment if ( $coerceType ne 'undef' ) { pdebug( 'coercing into %s', PPCDLEVEL2, $coerceType ); # Parameter has a specific data type to be coerced into if ( $coerceType eq 'string' && ref $value ne '' ) { # Coerce values into strings if ( ref $value eq 'ARRAY' ) { # Convert lists into a string using the list delimiter foreach (@$value) { s/"/\\"/smg; $_ = "\"$_\"" if /\Q$listDelim\E/sm; } $finalValue = join " $listDelim ", @$value; } elsif ( ref $value eq 'HASH' ) { # Convert hashes into a string using the hash & list # delimiters foreach ( sort keys %$value ) { $ivalue = $_; $ivalue =~ s/"/\\"/smg; $ivalue = "\"$ivalue\"" if /(?:\Q$hashDelim\E|\Q$listDelim\E)/sm; $$value{$_} = '' unless defined $$value{$_}; $$value{$_} = "\"$$value{$_}\"" if $$value{$_} =~ /(?:\Q$hashDelim\E|\Q$listDelim\E)/sm; push @elements, join " $hashDelim ", $_, ( defined $$value{$_} ? $$value{$_} : '' ); } $finalValue = join " $listDelim ", @elements; } else { # Try to stringify everything else $finalValue = "$value"; } } elsif ( $coerceType eq 'list' && ref $value ne 'ARRAY' ) { # Coerce value into a list if ( ref $value eq 'HASH' ) { # Convert hashes into a list $finalValue = []; foreach ( sort keys %$value ) { push @$finalValue, $_, $$value{$_}; } } elsif ( ref $value eq '' ) { # Convert strings into a list $self->_parse( split /\n/sm, "$$conf{$param}{Description}\n" . "$param $paramDelim $value" ); $finalValue = $$conf{$param}{Value}; } else { # Stringify everything else and put it into an array $finalValue = ["$value"]; } } elsif ( $coerceType eq 'hash' && ref $value ne 'HASH' ) { # Coerce value into a hash if ( ref $value eq 'ARRAY' ) { # Convert a list into a hash using every two elements # as a key/value pair push @$value, '' unless int( scalar @$value / 2 ) == scalar @$value / 2; $finalValue = {@$value}; } elsif ( ref $value eq '' ) { # Convert strings into a hash $self->_parse( split /\n/sm, "$$conf{$param}{Description}\n" . "$param $paramDelim $value" ); $finalValue = $$conf{$param}{Value}; } else { # Stringify everything else and put the value into the # hash key $finalValue = { "$value" => '' }; } } else { # No coercion is necessary $finalValue = $value; } } else { pdebug( 'no coercion to do', PPCDLEVEL2 ); $finalValue = $value; } $$conf{$param}{Value} = $finalValue; } else { pdebug( 'method in retrieve mode', PPCDLEVEL1 ); $rv = exists $$conf{$param} ? $$conf{$param}{Value} : exists $$defaults{$param} ? $$defaults{$param} : undef; } subPostamble( PPCDLEVEL1, '$', $rv ); return ref $rv eq 'HASH' ? (%$rv) : ref $rv eq 'ARRAY' ? (@$rv) : $rv; } sub coerce { # Purpose: Assigns the passed list to a data type and attempts to # coerce each existing value into that data type. # Returns: True or false. # Usage: $rv = $obj->coerce($type, @fields); my $self = shift; my $type = shift; my $itype = defined $type ? $type : 'undef'; my @params = @_; my $rv = 1; croak 'Mandatory first argument must be "string", "list", or "hash"' unless $itype eq 'string' or $itype eq 'list' or $itype eq 'hash'; croak 'Remaining arguments must be defined parameter names' unless @params; subPreamble( PPCDLEVEL1, '$$@', $self, $type, @params ); foreach (@params) { if (defined) { # Mark the parameter $$self{COERCE}{$_} = $type; $self->parameter( $_, $$self{CONF}{$_}{Value} ) if exists $$self{CONF}{$_}; } else { # Report undefined parameter names Parse::PlainConfig::Legacy::ERROR = pdebug( 'passed undefined parameter names to coerce', PPCDLEVEL1 ); $rv = 0; } } subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } sub describe { # Purpose: Assigns descriptive comments to specific parameters # Returns: True # Usage: $obj->describe(%descriptions); my $self = shift; my $conf = $$self{CONF}; my $coerce = $$self{COERCE}; my %new = (@_); subPreamble( PPCDLEVEL1, '$', $self ); # TODO: Consider allowing comment tags to be specified # TODO: Consider line splitting and comment tag prepending where # TODO: it's not already done. foreach ( keys %new ) { pdebug( '%s is described as \'%s\'', PPCDLEVEL1, $_, $new{$_} ); unless ( exists $$conf{$_} ) { $$conf{$_} = {}; if ( exists $$coerce{$_} ) { $$conf{$_}{Value} = $$coerce{$_} eq 'list' ? [] : $$coerce{$_} eq 'hash' ? {} : ''; } else { $$conf{$_}{Value} = ''; } } $$conf{$_}{Description} = $new{$_}; } subPostamble( PPCDLEVEL1, '$', 1 ); return 1; } sub order { # Purpose: Gets/sets order of parameters in file # Returns: Ordered list of named parameters # Usage: @params = $obj->order; # Usage: @params = $obj->order(@newOrder); my $self = shift; my $order = $$self{ORDER}; my @new = (@_); pdebug( 'entering w/(%s)', PPCDLEVEL1, @new ); @$order = (@new) if scalar @new; pdebug( 'leaving w/rv: %s', PPCDLEVEL1, @$order ); return @$order; } sub _parse { # Purpose: Parses the passed list of lines and extracts comments, # fields, and values and storing everything into the CONF # hash # Returns: True or false # Usage: $rv = $obj->_parse(@lines); my $self = shift; my $conf = $$self{CONF}; my $order = $$self{ORDER}; my $smart = $$self{SMART_PARSER}; my $tagDelim = $$self{PARAM_DELIM}; my $hashDelim = $$self{HASH_DELIM}; my $listDelim = $$self{LIST_DELIM}; my @lines = @_; my $rv = 1; my ( $i, $line, $comment, $entry, $field, $value ); my ( $indentation, $data, $saveEntry ); # Make sure some of the properties are sane croak 'LIST_DELIM and HASH_DELIM cannot be the same character sequence!' unless $$self{LIST_DELIM} ne $$self{HASH_DELIM}; subPreamble( PPCDLEVEL1, '$', $self ); # Flatten lines using an explicit backslash for ( $i = 0; $i <= $#lines; $i++ ) { # Let's disable uninitialized warnings since there's a few # places here we really don't care no warnings 'uninitialized'; if ( $lines[$i] =~ /\\\s*$/sm ) { pdebug( 'joining lines %s & %s', PPCDLEVEL2, $i + 1, $i + 2 ); # Lop off the trailing whitespace and backslash, preserving # only one space on the assumption that if it's there it's a # natural word break. $lines[$i] =~ s/(\s)?\s*\\\s*$/$1/sm; # Concatenate the following line (if there is one) after stripping # off preceding whitespace if ( $i < $#lines ) { $lines[ $i + 1 ] =~ s/^\s+//sm; $lines[$i] .= $lines[ $i + 1 ]; splice @lines, $i + 1, 1; --$i; } } } $saveEntry = sub { # Saves the extracted data into the conf hash and resets # the vars. my ($type); ( $field, $value ) = ( $entry =~ /^\s*([^$tagDelim]+?)\s*\Q$tagDelim\E\s*(.*)$/sm ); pdebug( "saving data:\n\t(%s: %s)", PPCDLEVEL2, $field, $value ); if ( exists $$self{COERCE}{$field} ) { # Get the field data type from COERCE $type = $$self{COERCE}{$field}; } else { # Otherwise, try to autodetect data type $type = scalar quotewords( qr/\s*\Q$hashDelim\E\s*/sm, 0, $value ) > 1 ? 'hash' : scalar quotewords( qr/\s*\Q$listDelim\E\s*/sm, 0, $value ) > 1 ? 'list' : 'scalar'; } pdebug( 'detected type of %s is %s', PPCDLEVEL2, $field, $type ); # For all data types we should strip leading/trailing whitespace. # If they really want it they should quote it. $value =~ s/^\s+|\s+$//smg unless $type eq 'scalar'; # We'll apply quotewords to scalar values only if the smart parser is # not being used or if we're not coercing all values into scalar for # this field. # # I hate having to do this but I was an idiot in the previous versions # and this is necessary for backwards compatibility. if ( $type eq 'scalar' ) { $value = join '', quotewords( qr/\s*\Q$listDelim\E\s*/sm, 0, $value ) unless $smart && exists $$self{COERCE}{$field} && $$self{COERCE}{$field} eq 'scalar'; } elsif ( $type eq 'hash' ) { $value = { quotewords( qr/\s*(?:\Q$hashDelim\E|\Q$listDelim\E)\s*/sm, 0, $value ) }; } elsif ( $type eq 'list' ) { $value = [ quotewords( qr/\s*\Q$listDelim\E\s*/sm, 0, $value ) ]; } # Create the parameter record $$conf{$field} = {}; $$conf{$field}{Value} = $value; $$conf{$field}{Description} = $comment; push @$order, $field unless grep /^\Q$field\E$/sm, @$order; $comment = $entry = ''; }; # Process lines $comment = $entry = ''; while ( defined( $line = shift @lines ) ) { if ( $line =~ /^\s*(?:#.*)?$/sm ) { # Grab comments and blank lines pdebug( "comment/blank line:\n\t%s", PPCDLEVEL3, $line ); # First save previous entries if $entry has content &$saveEntry() and $i = 0 if length $entry; # Save the comments $comment = length($comment) > 0 ? "$comment$line\n" : "$line\n"; } else { # Grab configuration lines # If this is the first line of a new entry and there's no # PARAM_DELIM skip the line -- something must be wrong. # # TODO: Error out/raise exception unless ( length $entry || $line =~ /\Q$tagDelim\E/sm ) { pdebug( "skipping spurious text:\n\t%s", PPCDLEVEL3, $line ); next; } # Grab indentation characters and line content ( $indentation, $data ) = ( $line =~ /^(\s*)(.+)$/sm ); pdebug( "data line:\n\t%s", PPCDLEVEL3, $data ); if ($smart) { # Smart parsing is enabled if ( length $entry ) { # There's current content if ( length($indentation) > $i ) { # If new indentation is greater than original # indentation we concatenate the lines as a # continuation $entry .= $data; } else { # Otherwise we treat this a a new entry, so we save # the old and store the current &$saveEntry(); ( $i, $entry ) = ( length($indentation), $data ); } } else { # No current content, so just store the current data and # continue processing ( $i, $entry ) = ( length($indentation), $data ); } } else { # Smart parsing is disabled, so treat every line as a new # entry $entry = $data; &$saveEntry(); } } } &$saveEntry() if length $entry; subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } sub _wrap { # Purpose: Parses the passed line of test and inserts indentation and # line breaks as needed # Returns: Formated string # Usage: $out = $obj->_wrap($fIndent, $sIndent, $textWidth, # $lineBreak, $paragraph); my $firstIndent = shift; my $subIndent = shift; my $textWidth = shift; my $lineBreak = shift; my $paragraph = shift; my ( @lines, $segment, $output ); subPreamble( PPCDLEVEL2, '$$$$p', $firstIndent, $subIndent, $textWidth, $lineBreak, $paragraph ); # Expand tabs in everything -- sorry everyone ($firstIndent) = expand($firstIndent); ($subIndent) = expand($subIndent); $paragraph = expand("$firstIndent$paragraph"); $lines[0] = ''; while ( length($paragraph) > 0 ) { # Get the next string segment (splitting on whitespace) ($segment) = ( $paragraph =~ /^(\s*\S+\s?)/sm ); if ( length $segment <= $textWidth - length $lines[-1] ) { # The segment will fit appended to the current line, # concatenate it $lines[-1] .= $segment; } elsif ( length $segment <= $textWidth - length $subIndent ) { # The segment will fit into the next line, add it $lines[-1] .= $lineBreak; push @lines, "$subIndent$segment"; } else { # Else, split on the text width $segment = $#lines == 0 ? substr $paragraph, 0, $textWidth : substr $paragraph, 0, $textWidth - length $subIndent; if ( length $segment > $textWidth - length $lines[-1] ) { $lines[-1] .= $lineBreak; push @lines, ( $#lines == 0 ? $segment : "$subIndent$segment" ); } else { $lines[-1] .= $segment; } } $paragraph =~ s/^.{@{[length($segment)]}}//sm; } $lines[-1] .= "\n"; $output = join '', @lines; subPostamble( PPCDLEVEL1, 'p', $output ); return $output; } sub hasParameter { # Purpose: Checks to see if the specified parameter exists as a # configuration parameter # Returns: True or false # Usage: $rv = $obj->hasParameter($name); my $self = shift; my $param = shift; my $rv = 0; my @params = ( keys %{ $self->{CONF} }, keys %{ $self->{DEFAULTS} }, ); croak 'Mandatory first parameter must be a defined parameter name' unless defined $param; subPreamble( PPCDLEVEL1, '$$', $self, $param ); $rv = scalar grep /^\Q$param\E$/sm, @params; subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } 1; __END__ =head1 NAME Parse::PlainConfig::Legacy - Parsing engine Legacy for Parse::PlainConfig =head1 VERSION $Id: lib/Parse/PlainConfig/Legacy.pm, 3.07 2024/01/10 13:32:06 acorliss Exp $ =head1 SYNOPSIS use Parse::PlainConfig::Legacy; $conf = new Parse::PlainConfig::Legacy; $conf = Parse::PlainConfig->new( 'PARAM_DELIM' => '=', 'FILE' => '.myrc', 'MAX_BYTES' => 65536, 'SMART_PARSER => 1, ); $conf->property(PARAM_DELIM => '='); $rv = $conf->read('myconf.conf'); $rv = $conf->read; $rv = $conf->readIfNewer; $conf->write('.myrc', 2); $conf->purge; @parameters = $conf->parameters; $conf->parameter(FOO => "bar"); $value = $conf->parameter(FOO); $conf->describe(FOO => 'This is foo'); $conf->coerce("string", qw(FOO BAR)); @order = $conf->order; $conf->order(@new_order); $errstr = Parse::PlainConfig::Parse::PlainConfig::Legacy::ERROR; $rv = $conf->hasParameter('FOO'); =head1 DESCRIPTION Parse::PlainConfig::Legacy provides OO objects which can parse and generate human-readable configuration files. =head1 SUBROUTINES/METHODS =head2 new $conf = new Parse::PlainConfig; $conf = Parse::PlainConfig->new( 'PARAM_DELIM' => '=', 'FILE' => '.myrc', 'MAX_BYTES' => 65536, 'SMART_PARSER => 1, ); The object constructor can be called with or without arguments. Arguments available for use include: Argument Default Purpose ============================================================= ORDER [] Specifies specific order of fields to be used while writing FILE undef Filename for read/write ops PARAM_DELIM ':' Field/value delimiter LIST_DELIM ',' List delimiter within field values HASH_DELIM '=>' Hash key/value delimiter within field values AUTOPURGE 0 Autopurge enabled/disabled COERCE {} Field coercion hash DEFAULTS {} Default field values SMART_PARSER 0 Smart parser enabled/disabled MAX_BYTES 16384 Integer denoting maximum bytes to read in any given file DEFAULTS {} Specifies default values for config parameters if not specified/parsed B is a hash of field name/data type pairs. If a field is listed in this hash then their values will always be returned in the requested format of either string, list, or hash. Any field coerced to string, for instance, will ignore list and hash delimiters and assume the entire value will always be string value. B is a hash of field name/value pairs. This ensures that even if a field is not explicitly set (either in a conf file or programmatically) a default value can still be retrieved. B removes the need to backslash end-of-lines to continue the value onto the next. If the following line is indented further than the tag was it will automatically assume that the next line is a continuation of the previous. It also affects the need to encapsulate coerced datatypes with quotation marks for irrelevant delimiters. B erases all stored parameters and values and applies the defaults (if any) before reading a file. This does not, however, erase any values set for B. =head2 property $conf->property(PARAM_DELIM => '='); This method sets or retrieves the specified property. Please note that this B the current value, even for those properties that are references to lists and hashes. If you're using this to set a property it will return a boolean true or false depending on the success of the operation. If you're just retrieving a property it will return the value of the property. If you ask for a nonexistent property it will B. B As of version 2.07 all hashes and lists are copied both in and out of the object, so any alterations to a referenced structure retrieved will have no effect on the property within the object. =head2 purge $conf->purge; This method performs an immediate manual purge. Auto-purge mode clears the configuration hash each time a configuration file is read, so that the internal configuration data consists solely of what is in that file. If you wanted to combine the settings of multiple files that each may exclusively hold some directives, setting this to 'off' will load the combined configuration as you read each file. You can still clobber configuration values, of course, if the same directive is defined in multiple files. In that case, the last file's value will be the one stored in the hash. This does not clear the B or B properties. Autopurge mode is disabled by default. =head2 read $rv = $conf->read('myconf.conf'); $rv = $conf->read; The read method is called initially with a filename as the only argument. This causes the parser to read the file and extract all of the configuration directives from it. You'll notice that you can also call the read method without an argument. The name of the file read is stored internally, and if already set to a valid value (either by a previous call to B with a filename argument or by setting the B property) this will read that file's contents. The return value will be one if the file was successfully read and parsed, or zero otherwise. The reason for failure can be read via B. This function will cause the program to croak if called without a filename ever being defined. =head2 readIfNewer $rv = $conf->readIfNewer; This method is used to reread & parse the file only if the mtime appears newer than when last read. If the file was successfully reread or appears to be the same it will return true. Any errors will be stored in B and it will return a false value. You can determine whether or not the file was read by the true value. If it was re-read it will return 1. If the file appears to be the same age it will return a 2. =head2 write $conf->write('.myrc', 2); This method writes the current configuration stored in memory to the specified file, either specified as the first argument, or as stored from an explicit or implicit B call. The second argument specifies what kind of whitespace padding, if any, to use with the directive/value delimiter. The following values are recognised: Value Meaning ================================================ 0 No padding (i.e., written as KEY:VALUE) 1 Left padding (i.e., written as KEY :VALUE) 2 Right padding (i.e., written as KEY: VALUE) 3 Full padding (i.e., written as KEY : VALUE) Both arguments are optional. =head2 parameters @parameters = $conf->parameters; This method returns a list of all the names of the directives currently stored in the configuration hash in no particular order. =head2 parameter $value = $conf->parameter('SCALAR1'); @values = $conf->parameter('LIST1'); %values = $conf->parameter('HASH1'); $conf->parameter('SCALAR1', "foo"); $conf->parameter('LIST1', [qw(foo bar)]); $conf->parameter('HASH1', { foo => 'bar' }); This method sets or retrieves the specified parameter. Hash and list values are copied and returned as a list. If the specified parameter is set to be coerced into a specific data type the specified value will be converted to that datatype. This means you can do something like: # SCALAR1 will equal "foo , bar , roo" assuming LIST_DELIM is set to ',' $conf->coerce(qw(string SCALAR1)); $conf->parameter('SCALAR1', [qw(foo bar roo)]); # SCALAR1 will equal "foo => bar : roo => ''" assuming HASH_DELIM is set # to '=>' and LIST_DELIM is set to ':' $conf->parameter('SCALAR1', { 'foo' => 'bar', 'roo' => '' }); In order for conversions to be somewhat predictable (in the case of hashes coerced into other values) hash key/value pairs will be assigned to string or list portions according to the alphabetic sort order of the keys. =head2 coerce $conf->coerce("string", "FOO", "BAR"); This method configures the parser to coerce values into the specified datatype (either string, list, or hash) and immediately convert any existing values and store them into that datatype as well. B Coercing existing values into another data type can provide for some interesting conversions. Strings, for instance, are split on the list delimiter when converting to arrays, and similarly on list and hash delimiters for hashes. Going from a hash or list to a string is done in the opposite manner, elements/key-value pairs are joined with the applicable delimiters and concatenated into a string. For this reason one should try to avoid coercing one data type into another if you can avoid it. Instead one should predefine what the data types for each parameter should be and define that in the COERCE hash passed during object instantiation, or via this method prior to reading and parsing a file. =head2 describe $conf->describe(KEY1 => 'This is foo', KEY2 => 'This is bar'); The describe method takes any number of key/description pairs which will be used as comments preceding the directives in any newly written conf file. You are responsible for prepending a comment character to each line, as well as splitting along your desired text width. =head2 order @order = $conf->order; $conf->order(@new_order); This method returns the current order of the configuration directives as read from the file. If called with a list as an argument, it will set the directive order with that list. This method is probably of limited use except when you wish to control the order in which directives are written in new conf files. Please note that if there are more directives than are present in this list, those extra keys will still be included in the new file, but will appear in alphabetically sorted order at the end, after all of the keys present in the list. =head2 hasParameter $rv = $conf->hasParameter('FOO'); This function allows you to see if a parameter has been defined or has a default set for it. Returns a boolean value. =head1 DEPRECATED METHODS =head2 delim $conf->delim('='); This method gets and/or sets the parameter name/value delimiter to be used in the conf files. The default delimiter is ':'. This can be multiple characters. =head2 directives @directives = $conf->directives; This method returns a list of all the names of the directives currently stored in the configuration hash in no particular order. =head2 get $field = $conf->get('KEY1'); ($field1, $field2) = $conf->get(qw(KEY1 KEY2)); The get method takes any number of directives to retrieve, and returns them. Please note that both hash and list values are passed by reference. In order to protect the internal state information, the contents of either reference is merely a copy of what is in the configuration object's hash. This will B pass you a reference to data stored internally in the object. Because of this, it's perfectly safe for you to shift off values from a list as you process it, and so on. =head2 set $conf->set(KEY1 => 'foo', KEY2 => 'bar'); The set method takes any number of directive/value pairs and copies them into the internal configuration hash. =head2 get_ref $href = $conf->get_ref B: This used to give you a reference to the internal configuration hash so you could manipulate it directly. It now only gives you a B of the internal hash (actually, it's reconstructed has to make it look like the old data structure). In short, any changes you make to this hash B. =head2 error warn $conf->error; This method returns a zero-length string if no errors were registered with the last operation, or a text message describing the error. =head2 ERROR $error = Parse::PlainConfig::ERROR(); Lvalue subroutine storing the last error which may have occurred. =head1 DEPENDENCIES =over =item o L =item o L =item o L =back =head1 FILE SYNTAX =head2 TRADITIONAL USAGE The plain parser supports the reconstructions of relatively simple data structures. Simple string assignments and one-dimensional arrays and hashes are possible. Below are are various examples of constructs: # Scalar assignment FIRST_NAME: Joe LAST_NAME: Blow # Array assignment FAVOURITE_COLOURS: red, yellow, green ACCOUNT_NUMBERS: 9956-234-9943211, \ 2343232-421231445, \ 004422-03430-0343 # Hash assignment CARS: crown_vic => 1982, \ geo => 1993 As the example above demonstrates, all lines that begin with a '#' (leading whitespace is allowed) are ignored as comments. if '#" occurs in any other position, it is accepted as part of the passed value. This means that you B place comments on the same lines as values. All directives and associated values will have both leading and trailing whitespace stripped from them before being stored in the configuration hash. Whitespace is allowed within both. In traditional mode (meaning no parameters are set to be coerced into a specific datatype) one must encapsulate list and hash delimiters with quotation marks in order to prevent the string from being split and stored as a list or hash. Quotation marks that are a literal part of the string must be backslashed. =head2 SMART PARSER The new parser now provides some options to make the file syntax more convenient. You can activate the smart parser by setting B to a true value during object instantiation or via the B method. With the traditional parser you had to backslach the end of all preceding lines if you wanted to split a value into more than one line: FOO: This line starts here \ and ends here... With the smart parser enabled that is no longer necessary as long as the following lines are indented further than the first line: FOO: This line starts here and ends here... B The indentation is compared by byte count with no recognition of tab stops. That means if you indent with spaces on the first line and indent with tabs on the following it may not concantenate those values. Another benefit of the smart parser is found when you specify a parameter to be of a specific datatype via the B hash during object instantiation or the B method. For instance, the traditional parser requires you to encapsulate strings with quotation marks if they contain list or hash delimiters: Quote: "\"It can't be that easy,\" he said." Also note how you had to escape quotation marks if they were to be a literal part of the string. With this parameter set to be coerced to a scalar you can simply write: Quote: "It can't be that easy," he said. Similarly, you don't have to quote hash delimiters in parameters set to be coerced into lists. Quotation marks as part of an element value must be escaped, though, since unescaped quotation marks are assumed to encapsulate strings containing list delimiters you don't want to split on. B The previous versions of Parse::PlainConfig did not allow the user to set keys like: FOO: \ bar or save empty assignments like FOO: This is no longer the case. Both are now valid and honoured. =head1 SECURITY B This parser will attempt to open what ever you pass to it for a filename as is. If this object is to be used in programs that run with permissions other than the calling user, make sure you sanitize any user-supplied filename strings before passing them to this object. This also uses a blocking b call to open the file for reading and writing. =head1 DIAGNOSTICS Through the use of B this module will produce internal diagnostic output to STDERR. It begins logging at log level 7. To enable debugging output please see the pod for L. =head1 BUGS AND LIMITATIONS =head1 AUTHOR Arthur Corliss (corliss@digitalmages.com) =head1 LICENSE AND COPYRIGHT This software is licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information. (c) 2002 - 2023, Arthur Corliss (corliss@digitalmages.com) Parse-PlainConfig-3.07/lib/Parse/PlainConfig/Constants.pm0000644000175000001440000000743514547615346023015 0ustar acorlissusers# Parse::PlainConfig::Constants -- PPC Constants # # (c) 2016 - 2013, Arthur Corliss # # $Id: lib/Parse/PlainConfig/Constants.pm, 3.07 2024/01/10 13:32:06 acorliss Exp $ # # This software is licensed under the same terms as Perl, itself. # Please see http://dev.perl.org/licenses/ for more information. # ##################################################################### ##################################################################### # # Environment definitions # ##################################################################### package Parse::PlainConfig::Constants; use 5.008; use strict; use warnings; use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS); use Exporter; use Class::EHierarchy qw(:all); use Paranoid::Debug; use base qw(Exporter); ($VERSION) = ( q$Revision: 3.07 $ =~ /(\d+(?:\.(\d+))+)/sm ); use constant PPCDLEVEL1 => PDEBUG6; use constant PPCDLEVEL2 => PDEBUG7; use constant PPCDLEVEL3 => PDEBUG8; use constant PPC_DEF_SIZE => 65_536; use constant MTIME => 9; use constant DEFAULT_PDLM => ':'; use constant DEFAULT_LDLM => ','; use constant DEFAULT_HDLM => '=>'; use constant DEFAULT_CMMT => '#'; use constant DEFAULT_SUBI => 8; use constant DEFAULT_TAB => 8; use constant DEFAULT_TW => 78; use constant DEFAULT_HDOC => 'EOF'; use constant PPC_SCALAR => CEH_SCALAR; use constant PPC_ARRAY => CEH_ARRAY; use constant PPC_HASH => CEH_HASH; use constant PPC_HDOC => 1024; @EXPORT = qw(PPC_SCALAR PPC_ARRAY PPC_HASH PPC_HDOC); @EXPORT_OK = ( @EXPORT, qw(PPCDLEVEL1 PPCDLEVEL2 PPCDLEVEL3 PPC_DEF_SIZE MTIME DEFAULT_TW DEFAULT_PDLM DEFAULT_LDLM DEFAULT_HDLM DEFAULT_CMMT DEFAULT_SUBI DEFAULT_TAB DEFAULT_HDOC) ); %EXPORT_TAGS = ( all => [@EXPORT_OK], std => [@EXPORT], debug => [qw(PPCDLEVEL1 PPCDLEVEL2 PPCDLEVEL3)], ); ##################################################################### # # Module code follows # ##################################################################### 1; __END__ =head1 NAME Parse::PlainConfig::Constants - PPC Constants =head1 VERSION $Id: lib/Parse/PlainConfig/Constants.pm, 3.07 2024/01/10 13:32:06 acorliss Exp $ =head1 SYNOPSIS use Parse::PlainConfig::Constants; $scalarType = PPC_SCALAR; $arrayType = PPC_ARRAY; $hashType = PPC_HASH; $hdocType = PPC_HDOC; =head1 DESCRIPTION This module provides a number of constants that are used mostly internally. That said, the default export provides the basic data types you'll need to declare your parameter types. You can also export debug level constants to provide trace information out to B. =head1 SUBROUTINES/METHODS None. =head1 CONSTANTS THere are three export sets provided by this module: Set Description ---------------------------------------------------- std Parameter data type constants debug Debug level constants all All constants (including internall constants =head2 std =head3 PPC_SCALAR Scalar data type. Leading and trailing white space is trimmed. =head3 PPC_ARRAY Array data type. Leading and trailing white space for all elements is trimmed. =head3 PPC_HASH Hash data type. Leading and trailing white space for all keys and values is trimmed. =head3 PPC_HDOC Here doc data type. Functionally equivalent to L. =head2 debug The higher the debug level the more verbose the output. =head3 PPCDLEVEL1 =head3 PPCDLEVEL2 =head3 PPCDLEVEL3 =head2 all =head1 DEPENDENCIES =over =item o Exporter =back =head1 BUGS AND LIMITATIONS =head1 AUTHOR Arthur Corliss (corliss@digitalmages.com) =head1 LICENSE AND COPYRIGHT This software is licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information. (c) 2016 - 2023, Arthur Corliss (corliss@digitalmages.com) Parse-PlainConfig-3.07/lib/Parse/PlainConfig.pm0000644000175000001440000011253314547615346021035 0ustar acorlissusers# Parse::PlainConfig -- Parsing Engine for Parse::PlainConfig # # (c) 2002 - 2023, Arthur Corliss , # # $Id: lib/Parse/PlainConfig.pm, 3.07 2024/01/10 13:32:06 acorliss Exp $ # # This software is licensed under the same terms as Perl, itself. # Please see http://dev.perl.org/licenses/ for more information. # ##################################################################### ##################################################################### # # Environment definitions # ##################################################################### package Parse::PlainConfig; use 5.008; use strict; use warnings; use vars qw($VERSION); ($VERSION) = ( q$Revision: 3.07 $ =~ /(\d+(?:\.(\d+))+)/sm ); use Class::EHierarchy qw(:all); use Parse::PlainConfig::Constants qw(:all); use Parse::PlainConfig::Settings; use Text::ParseWords; use Text::Tabs; use Fcntl qw(:seek :DEFAULT); use Paranoid; use Paranoid::Debug; use Paranoid::IO; use Paranoid::IO::Line; use Paranoid::Input qw(:all); use Paranoid::Glob; use base qw(Class::EHierarchy); use vars qw(@_properties @_methods %_parameters %_prototypes); ##################################################################### # # Module code follows # ##################################################################### sub _findAllClasses { # Purpose: Returns a list of all parent class names # Returns: Array of scalars # Usage: @pclasses = _findAllClasses(ref $obj); my $class = shift; my ( @classes, %c, $c, @rv ); subPreamble( PPCDLEVEL3, '$', $class ); # Pull all parent class and recursively loop { no strict 'refs'; if ( defined *{"${class}::ISA"}{ARRAY} ) { foreach $c ( @{ *{"${class}::ISA"}{ARRAY} } ) { push @classes, _findAllClasses($c); } push @classes, $class if scalar @classes or grep { $_ eq __PACKAGE__ } @{ *{"${class}::ISA"}{ARRAY} }; } } # Consolidate redundant entries foreach $c (@classes) { push @rv, $c unless exists $c{$c}; $c{$c} = 1; } subPostamble( PPCDLEVEL3, '@', @rv ); return @rv; } sub _initialize { # Purpose: Initialize config object and loads class defaults # Returns: Boolean # Usage: $rv = $obj->_initialize(@args); my $obj = shift; my $class = ref $obj; my $rv = 1; my ( @classes, $settings, %new, %_globals, %_parameters, %_prototypes ); subPreamble( PPCDLEVEL1, '$$', $obj, $class ); # Create & adopt the settings object $settings = new Parse::PlainConfig::Settings; $obj->adopt($settings); $settings->alias('settings'); # Get a list of all parent classes @classes = ( _findAllClasses($class) ); # Read in class global settings unless ( __PACKAGE__ eq $class ) { foreach $class (@classes) { if ( defined *{"${class}::_globals"} ) { pdebug( 'loading globals from %s', PPCDLEVEL2, $class ); { no strict 'refs'; %new = %{ *{"${class}::_globals"}{HASH} }; } if ( scalar keys %new ) { foreach ( keys %new ) { $_globals{$_} = $new{$_}; pdebug( 'overriding %s with (%s)', PPCDLEVEL3, $_, $_globals{$_} ); $rv = 0 unless $settings->set( $_, $_globals{$_} ); } } } } foreach $class (@classes) { if ( defined *{"${class}::_parameters"} ) { pdebug( 'loading parameters from %s', PPCDLEVEL2, $class ); { no strict 'refs'; %new = %{ *{"${class}::_parameters"}{HASH} }; } if ( scalar keys %new ) { %_parameters = ( %_parameters, %new ); $settings->set( 'property types', %_parameters ); foreach ( keys %new ) { pdebug( 'creating property %s', PPCDLEVEL3, $_ ); unless ( _declProperty( $obj, $_, CEH_PUB | ( $_parameters{$_} == PPC_HDOC ? PPC_SCALAR : $_parameters{$_} ), ) ) { $rv = 0; last; } # merge property regex $settings->merge( 'property regexes', $_, qr#(\s*)(\Q$_\E)\s*\Q@{[ $settings->delimiter ]}\E\s*(.*)#s ); } } } if ( defined *{"${class}::_prototypes"} ) { pdebug( 'loading prototypes from %s', PPCDLEVEL2, $class ); { no strict 'refs'; %new = %{ *{"${class}::_prototypes"}{HASH} }; } if ( scalar keys %new ) { %_prototypes = ( %_prototypes, %new ); $settings->set( 'prototypes', %_prototypes ); foreach ( keys %new ) { # merge property meta-data $settings->merge( 'prototype regexes', $_, qr#(\s*)(\Q$_\E)\s+(\S+)\s*\Q@{[ $settings->delimiter ]}\E\s*(.*)#s ); } } } } } # Store all parent classes $settings->set( '_ppcClasses', @classes ); # Load the defaults $rv = $obj->parse( $obj->default ); subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } sub settings { # Purpose: Returns object reference to the settings object # Returns: Object reference # Usage: $settings = $obj->settings; my $obj = shift; return $obj->getByAlias('settings'); } sub _default { # Purpose: Returns the DATA block from the calling # Returns: Array # Usage: @lines = $obj->_default; my $obj = shift; my $class = shift; my ( $fn, @chunk, @lines ); subPreamble( PPCDLEVEL2, '$', $obj ); $class =~ s#::#/#sg; $class .= '.pm'; $fn = $INC{$class}; pdebug( 'attempting to read from %s', PPCDLEVEL3, $fn ); if ( popen( $fn, O_RDONLY ) ) { # Read in file while ( sip( $fn, @chunk ) and @chunk ) { push @lines, @chunk } # empty all lines prior to __DATA__ while ( @lines and $lines[0] !~ /^\s*__DATA__\s*$/s ) { shift @lines; } shift @lines; # empty all lines after __END__ if ( @lines and grep /^\s*__END__\s*$/s, @lines ) { while ( @lines and $lines[-1] !~ /^\s*__END__\s*$/s ) { pop @lines; } pop @lines; } pseek( $fn, 0, SEEK_SET ); } subPostamble( PPCDLEVEL2, '@', @lines ); return wantarray ? @lines : join '', @lines; } sub default { # Purpose: Returns the DATA block from the specified class, # or the object class if not specified # Returns: Array # Usage: @lines = $obj->default; # Usage: @lines = $obj->default($class); my $obj = shift; my @classes = $obj->getByAlias('settings')->get('_ppcClasses'); my ( $class, @rv ); subPreamble( PPCDLEVEL1, '$', $obj ); foreach $class (@classes) { push @rv, $obj->_default($class); } subPostamble( PPCDLEVEL1, '@', @rv ); return @rv; } sub get { # Purpose: Returns the value of the specified parameter # Returns: Scalar/List/Hash # Usage: $val = $obj->get('foo'); my $obj = shift; my $p = shift; my ( $valp, $valt, $rv ); subPreamble( PPCDLEVEL1, '$$', $obj, $p ); if ( defined $p ) { $valp = scalar grep /^\Q$p\E$/s, $obj->properties; if ($valp) { ($valt) = $obj->settings->subset( 'property types', $p ); $valt = PPC_SCALAR if $valt == PPC_HDOC; } } $obj->error( pdebug( 'specified invalid parameter name: %s', PPCDLEVEL1, $p ) ) unless $valp; # Return values get a little dicier because of different data types if ( defined $valt ) { if ( $valt == PPC_SCALAR ) { $rv = $obj->SUPER::get($p); subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } elsif ( $valt == PPC_ARRAY ) { $rv = [ $obj->SUPER::get($p) ]; subPostamble( PPCDLEVEL1, '@', @$rv ); return @$rv; } else { $rv = { $obj->SUPER::get($p) }; subPostamble( PPCDLEVEL1, '%', %$rv ); return %$rv; } } subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } sub set { # Purpose: Assigns the desired values to the specified parameter # Returns: Boolean # Usage: $rv = $obj->set($prop, @values); my $obj = shift; my $p = shift; my @vals = @_; my %propTypes = $obj->settings->propertyTypes; my ( $valp, $rv ); subPreamble( PPCDLEVEL1, '$$@', $obj, $p, @vals ); if ( defined $p ) { $valp = scalar grep /^\Q$p\E$/s, $obj->properties; } $obj->error( pdebug( 'specified invalid parameter name: %s', PPCDLEVEL1, $p ) ) unless $valp; if ($valp) { if (@vals) { # Set whatever's assigned $rv = $obj->SUPER::set( $p, @vals ); } else { # Assume that no values means empty/undef if ( $propTypes{$p} == PPC_SCALAR or $propTypes{$p} == PPC_HDOC ) { $rv = $obj->SUPER::set( $p, undef ); } else { $rv = $obj->empty($p); } } } subPostamble( PPCDLEVEL1, '$', $valp ? $rv : undef ); return $valp ? $rv : undef; } sub _snarfBlock (\@\$\$$) { # Purpose: Finds and returns the block with the value # string extracted. # Returns: Boolean # Usage: $rv = _snarfBlock(@lines, $val); my $lref = shift; my $pref = shift; my $vref = shift; my $settings = shift; my $obj = $settings->parent; my %regex = $settings->propertyRegexes; my %pregex = $settings->prototypeRegexes; my %propTypes = $settings->propertyTypes; my %prototypes = $settings->prototypes; my $subi = $settings->subindentation; my ( $rv, $indent, $prop, $proto, $trailer, $iwidth, $line, $preg ); subPreamble( PPCDLEVEL2, '$$$$', $lref, $pref, $vref, $settings ); # Match line to a property/prototype declaration # # First try to match against properties foreach ( keys %regex ) { if ( $$lref[0] =~ /^$regex{$_}$/s ) { ( $indent, $prop, $trailer ) = ( $1, $2, $3 ); $rv = 1; shift @$lref; last; } } unless ( $rv and defined $prop and length $prop ) { foreach ( keys %pregex ) { if ( $$lref[0] =~ /^$pregex{$_}$/s ) { ( $indent, $proto, $prop, $trailer ) = ( $1, $2, $3, $4 ); $rv = 1; shift @$lref; last; } } } # Define all prototyped properties if ( defined $proto and length $proto ) { if ( defined $prop and length $prop ) { if ( exists $regex{$prop} ) { $obj->error( pdebug( 'token (%s) for prototype (%s) attempted to override property', PPCDLEVEL1, $prop, $proto ) ); $rv = 0; } else { if ( exists $propTypes{$prop} ) { # Make sure they haven't been previously defined, # or if they have, they match the same type unless ( $propTypes{$prop} == $prototypes{$proto} ) { $rv = 0; $obj->error( pdebug( 'prototype mismatch with previous declaration: %s', PPCDLEVEL1, $proto ) ); pdebug( 'current type: %s prototype: %s', PPCDLEVEL1, $propTypes{$prop}, $prototypes{$proto} ); } } else { # Create a new property pdebug( 'creating property based on prototype %s: %s', PPCDLEVEL3, $proto, $prop ); $rv = _declProperty( $obj, $prop, CEH_PUB | ( $prototypes{$proto} == PPC_HDOC ? PPC_SCALAR : $prototypes{$proto} ), ); # Record the prop type if ($rv) { $settings->merge( 'property types', $prop, $propTypes{$prop} = $prototypes{$proto} ); ($preg) = $settings->subset( 'prototype registry', $proto ); $preg = [] unless defined $preg; push @$preg, $prop; $settings->merge( 'prototype registry', $proto => $preg ); } else { $obj->error( pdebug( 'failed to declare prototype: %s %s', PPCDLEVEL1, $proto, $prop ) ); } } } } else { $obj->error( pdebug( 'invalid token used for prototype %s: %s', PPCDLEVEL1, $proto, $prop ) ); $rv = 0; } } # Grab additional lines as needed if ($rv) { if ( $propTypes{$prop} == PPC_HDOC ) { # Snarf all lines until we hit the HDOC marker $rv = 0; while (@$lref) { $line = shift @$lref; if ( $line =~ /^\s*\Q@{[ $settings->hereDoc ]}\E\s*$/s ) { $rv = 1; last; } else { $line =~ s/^\s{1,$subi}//s; $trailer .= $line; } } # Error out if we never found the marker $obj->error( pdebug( 'failed to find the here doc marker', PPCDLEVEL1 ) ) unless $rv; } else { # All non-HDOCs are handled the same $iwidth = defined $indent ? length $indent : 0; while (@$lref) { # We're done if this is a line break last if $$lref[0] =~ /^\s*$/s; # We're also done if indentation isn't greater # than the parameter declaration line ($indent) = ( $$lref[0] =~ /^(\s*)/s ); last if !defined $indent or $iwidth >= length $indent; # Append content to the trailer $line = shift @$lref; $line =~ s/^\s{1,$subi}//s; pchomp($line); $trailer .= $line; } } $trailer =~ s/\s+$//s if defined $trailer; } if ($rv) { pchomp($trailer); ( $$pref, $$vref ) = ( $prop, $trailer ); pdebug( 'extracted value for %s: %s', PPCDLEVEL3, $prop, $trailer ); } subPostamble( PPCDLEVEL2, '$', $rv ); return $rv; } sub _snarfProp { # Purpose: Takes the property value and parses according to its type, # then merges it # Returns: Boolean # Usage: $rv = _snarfProp($obj, $prop, $val); my $obj = shift; my $prop = shift; my $val = shift; my $settings = $obj->settings; my %propTypes = $settings->propertyTypes; my $ldelim = $settings->listDelimiter; my $hdelim = $settings->hashDelimiter; my $rv = 1; my @elements; subPreamble( PPCDLEVEL2, '$$$', $obj, $prop, $val ); if ( $propTypes{$prop} == PPC_HDOC or $propTypes{$prop} == PPC_SCALAR ) { # Here Docs and scalars are merged as-is $obj->SUPER::set( $prop, $val ); } else { if ( $propTypes{$prop} == PPC_ARRAY ) { # Split into a list @elements = quotewords( qr/\Q$ldelim\E/s, 0, $val ); foreach (@elements) { s/^\s+//s; s/\s+$//s; } } else { # Split into a hash @elements = quotewords( qr/(?:\Q$ldelim\E|\Q$hdelim\E)/s, 0, $val ); foreach (@elements) { s/^\s+//s; s/\s+$//s; } } # merge the list value pdebug( 'storing in %s: %s', PPCDLEVEL3, $prop, @elements ); $obj->empty($prop); $obj->SUPER::set( $prop, @elements ); } subPostamble( PPCDLEVEL2, '$', $rv ); return $rv; } sub parse { # Purpose: Parses passed content and extracts values # Returns: Boolean # Usage: $rv = $obj->parse(@lines); my $obj = shift; my @lines = @_; my $settings = $obj->settings; my $delim = $settings->delimiter; my $cre = qr#^\s*\Q@{[ $settings->comment ]}\E#s; my $rv = 1; my ( $text, $prop, $value, $glob ); subPreamble( PPCDLEVEL1, '$@', $obj, @lines ); # Some preprocessing of lines if (@lines) { $tabstop = $settings->tabStop; @lines = expand(@lines); foreach (@lines) { $text = ( defined $text and length $text ) ? join "\n", $text, split NEWLINE_REGEX, $_ : join "\n", split NEWLINE_REGEX, $_; } } while (@lines) { # Skip comments and empty lines if ( $lines[0] =~ /^$cre/s or $lines[0] =~ /^\s*(?:@{[ NEWLINE_REGEX ]})?$/s ) { shift @lines; next; } # Handle "include" statements if ( $lines[0] =~ /^\s*include\s+(.+?)\s*$/s ) { $glob = new Paranoid::Glob globs => [$1]; shift @lines; $rv = 0 unless $obj->read($glob); next; } # See if we have property block if ( _snarfBlock( @lines, $prop, $value, $settings ) ) { # Parse the block (but preserve earlier errors) $rv = 0 unless _snarfProp( $obj, $prop, $value ); } else { pdebug( 'discarding invalid input: %s', PPCDLEVEL1, $lines[0] ); shift @lines; $rv = 0; } } subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } sub read { # Purpose: Reads the passed file(s) # Returns: Boolean # Usage: $rv = $obj->read($filename); my $obj = shift; my $source = shift; my ( $rv, @lines ); subPreamble( PPCDLEVEL1, '$$', $obj, $source ); if (@_) { # Work all entries passed if handed a list $rv = $obj->read($source); foreach (@_) { $rv = 0 unless $obj->read($_) } } elsif ( ref $source eq '' ) { # Treat all non-reference files as filenames if ( slurp( $source, @lines ) ) { $rv = $obj->parse(@lines); pdebug( 'errors parsing %s', PPCDLEVEL1, $source ) unless $rv; } else { $obj->error( pdebug( 'failed to read %s: %s', PPCDLEVEL1, $source, Paranoid::ERROR() ) ); } } elsif ( ref $source eq 'Paranoid::Glob' ) { # Handle Paranoid globs specially $rv = 1; foreach (@$source) { $rv = 0 unless $obj->read($_) } } else { # Handle everything else as if it was a glob if ( slurp( $source, @lines ) ) { $rv = $obj->parse(@lines); pdebug( 'errors parsing %s', PPCDLEVEL1, $source ) unless $rv; } else { $obj->error( pdebug( 'failed to read %s: %s', PPCDLEVEL1, $source, Paranoid::ERROR() ) ); } } subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } sub reset { # Purpose: Resets configuration state to defaults # Returns: Boolean # Usage: $rv = $obj->reset; my $obj = shift; my $settings = $obj->settings; my %propTypes = $settings->propertyTypes; my $rv; subPreamble( PPCDLEVEL1, '$', $obj ); # empty all property values foreach ( keys %propTypes ) { pdebug( 'clearing merged values for %s', PPCDLEVEL2, $_ ); if ( $propTypes{$_} == PPC_SCALAR or $propTypes{$_} == PPC_HDOC ) { $obj->SUPER::set( $_, undef ); } else { $obj->empty($_); } } $rv = $obj->parse( $obj->default ); subPostamble( PPCDLEVEL1, '$', $rv ); return $rv; } sub prototyped { # Purpose: Returns a list of properties that were created with # prototypes # Returns: Array # Usage: @protos = $obj->prototyped; # Usage: @protos = $obj->prototyped($proto); my $obj = shift; my $proto = shift; my ( %preg, @prval ); subPreamble( PPCDLEVEL1, '$$', $obj, $proto ); %preg = $obj->settings->get('prototype registry'); if ( defined $proto and length $proto ) { if ( exists $preg{$proto} ) { @prval = @{ $preg{$proto} }; } else { pdebug( 'no prototype properties declared w/%s', PPCDLEVEL2, $proto ); } } else { pdebug( 'dumping all declared prototyped properties', PPCDLEVEL2 ); foreach ( keys %preg ) { push @prval, @{ $preg{$_} } } } subPostamble( PPCDLEVEL1, '@', @prval ); return @prval; } sub error { # Purpose: Sets/gets the last error message # Returns: Scalar/undef # Usage: $errStr = $obj->error; # Usage: $errStr = $obj->error($msg); my $obj = shift; my $msg = shift; if ( defined $msg ) { $obj->settings->set( 'error', $msg ); } else { $msg = $obj->settings->get('error'); } return $msg; } 1; __END__ =head1 NAME Parse::PlainConfig - Configuration file class =head1 VERSION $Id: lib/Parse/PlainConfig.pm, 3.07 2024/01/10 13:32:06 acorliss Exp $ =head1 SYNOPSIS =head2 SAMPLE CONFIG CLASS package MyConfig; use Parse::PlainConfig; use Parse::PlainConfig::Constants; use base qw(Parse::PlainConfig); use vars qw(%_globals %_parameters %_prototypes); %_globals = ( 'comment' => '#', 'delimiter' => ':', 'list delimiter' => ',', 'hash delimiter' => '=>', 'subindentation' => 4, 'here doc' => 'EOF', ); %_parameters = ( 'daemon ports' => PPC_ARRAY, 'banner' => PPC_HDOC, 'user' => PPC_SCALAR, 'group' => PPC_SCALAR, 'database' => PPC_HASH, 'acls' => PPC_HASH, ); %_prototypes = ( 'define net' => PPC_ARRAY, ); 1; __DATA__ # This is the default configuration for MyConfig. # Newly created objects based on this class will # inherit the below configuration as default values. # # daemon ports: list of ports to listen on daemon ports: 8888, 9010 # banner: default banner to display on each connection banner: ******** WARNING ******** You are being watched ******** WARNING ******** EOF user: nobody group: nogroup database: host => localhost, db => mydb, user => dbuser, pass => dbpass define net loopback: 127.0.0.1/8, ::1/128 define net localnet: 192.168.0.0/24, 192.168.35.0/24 define net nonlocal: ! 192.168.0.0/16 acls: loopback => allow, localnet => allow, nonlocal => deny __END__ =head1 NAME normal pod text can be put here... =head2 SAMPLE OBJECT USAGE $config = new MyConfig; print "default user: ", $config->get('user'), "\n"; print "default group: ", $config->get('group'), "\n"; # Override value $config->set('user', 'root'); # Get config from a file $rv = $config->read($filename); # Parse config from in-memory text $rv = $config->parse(@lines); # Prototyps are accessed like parameters @localnets = $config->get('localnet'); # Reset config values back to class defaults $config->reset; # Print default config file print $config->default; =head1 DESCRIPTION B provides a simple way to write a config object class that supports all the basic primitive data types (scalar, array, and hashes) while allowing for arbitrary delimiters, comment characters, and more. The use of a B<__DATA__> block to merge your default config not only provides for a reference config but a convenient way to set default values for parameters and prototypes. Use of B<__END__> also allows you to append your standard POD text to allow for the creation of man pages documenting your configuration options. The parser supports the use of "include {filename|glob}" syntax for splitting configuration parameters amongst multiple config files. Even without it every call to L or L only applies new settings on top of the existing set, allowing you to aggregate multiple config file parameters into one set of parameters. Unlike previous versions of this module B is strictly a parser, not a generator. That functionality never seem to be used enough to be worth maintaining with this upgrade. For backwards compatibility the old Parser/Generator is still included under the new namespace L. Updating legacy scripts to use that package name instead should keep everything working. B is a subclass of L, and all parameters are public properties allowing access to the full set of data-aware methods provided by that module (such as B, B, B, B, and others). I/O is also done in a platform-agnostic manner, allowing parsed values to read reliably on any platform regardless of line termination style used to author the config file. =head1 SUBCLASSING All parsing objects are now subclasses of L tuned for a specific style and a known list of parameters and/or prototypes. This makes coding for config file parsing extremely simple and convenient. Control of the parser is performed by setting values in three class hashes: =head2 %_globals The B<%_globals> hash is primarily used to specify special character sequences the parser will key to identify comments and the various parameters and data types. The following key/value are supported: Key Default Description --------------------------------------------------------------- comment # Character(s) used to denote comments delimiter : Parameter/value delimiter list delimiter , Ordinal array values delimiter hash delimiter => Hash values' key/value pair delimiter subindentation 4 Default level of indentation to expect for line continuations here doc EOF Token used for terminating here doc parameter values If all of the defaults are acceptable this hash can be omitted entirely. Note that the I is merely advisory, any additional level of subindentation on line continuations will work. What this does, however, is trim up to that amount of preceding white space on each line within a here-doc. This allows one to indent blocks of text to maintain the visual flow of the config file, while still allowing the editor the use of all columns in the display. =head2 %_parameters The B<%_parameters> hash is used to list all of the formal parameters recognized by this config object. All parameters must be one of four data types: Type Description ---------------------------------------------------------------- PPC_SCALAR Simple strings PPC_ARRAY Arrays/lists PPC_HASH Hashes/Associative arrays PPC_HDOC Essentially a PPC_SCALAR that preserves formatting All but B will trim leading/trailing white space and collapse all lines into a single line for parsing. That means that no string, ordinal value, key, or associative value can have embedded line breaks. You can, however, have delimiter characters as part of any values as long as they are encapusated in quoted text or escaped. B will preserve line breaks, but will trim leading white space on each line up to the value given to B<$_globals{subindentation}>. =head2 %_prototypes B<%_prototypes> exist to allow for user-defined parameters that fall outside of the formal parameters in B<%_parameters>. ACLs, for instance, are often of indeterminate number and naming, which is a perfect use-case for prototypes. Like parameters prototypes are assigned a data type. Unlike parameters prototypes are assigned types based on a declarative preamble since the the name (or token) is not known in advance. To continue with the ACL example we could define a prototype like so: %_prototypes = ( 'define acl' => PPC_ARRAY ); The config editor could then define any number of ACLs: define acl loopback 127.0.0.1/8 define acl localnet 192.168.0.0/24,192.168.1.0/24 Once parsed those ACL parameters can then be accessed simply by their unique token: @localnets = $config->get('localnet'); =head2 NOTES ON SUBCLASSING The above section provided the rudimentaries of subclassing L, but this module also subclassing your config modules as well, including multiple inheritance. This can allow you to have a single config that can consolidate multiple configurations in a single file. There's only a few rules to observe: =over =item * All configs must use the same global parsing parameters =item * Each property and prototype should use be declared in one specific class to avoid conflicts with data types and potential defaults in the DATA block =item * Defaults from each class will be applied from the top down, and left to right. This means that the top level parent class'es data block will be parsed first, then each subsequent child class, and the final subclass, last. =back =head1 CONFIG FILE FORMAT RULES This module is intended to provide support for parsing human-readable config files, while supporting basic data structures and delimiter flexibility. That said, there are a few basic rules by which the parser operates. Note that the use B<__DATA__> and/or B<__END__> blocks are entirely optional. =head2 DELIMITERS Delimiters must be unique. You cannot use the same character(s) for both list delimiters and hash key/value pair delimiters, for instance. That said, the parser is very forgiving on the use of whitespace around all delimiters, even if one of your delimiters is literally a space. Hash and array delimiters can be embedded in elements as long as they're quoted or escaped appropriately. Those elements are split using L' L function. =head2 LINE CONTINUATIONS Parameters values may need to be, by necessity, longer than a single line. This is fully supported for all data types. All that is needed that the line continuations be at least one space more indented than the preceding line. Empty lines are considered to be line breaks which terminate the parameter value. Likewise, a line that is indented equal or less than the parameter declaration line implies a new block of content. There is one exception to that rule: here docs. If you need to preserve formatting, which can include line breaks, the use of here docs will suck in everything up to the next here doc EOF token. The entire here doc, however, is treated as scalar value for purposes of parameter storage. =head2 COMMENTS Comments can be any sequence of characters, but must be on a line by themselves. Preceding white space is allowed. =head2 PARAMETER NAMES Given that parameters are actually formal object properties it could go without saying that each parameter must be uniquely named. Parameters names can include white space or other miscellaneous punctuation. =head2 PROTOTYPES Prototypes allow for the dynamic creation of parameters. There are a few caveats in their usage, however. Prototypes are specified through a unique preamble followed by a unique token. Unlike parameter names this token cannot have embedded white space. But like parameters they are specified by that unique token (minus the preamble) during L and L operations. Since these dynamic properties are also formal properties the token must not be in use as a formal property. In other words, all prototype tokens and parameter names must be unique as a set. Parsing errors will be generated if the token occurs as a formal parameter. It will also be generated if you attempt to redfine a token as a different type of data structure. =head1 SUBROUTINES/METHODS =head2 new $conf = new MyConfig; This creates a new config object based on the specified config class, initialized with the defaults merged in B<__DATA__>. No additional arguments are supported. This will fail if the default config is invalid in any way. =head2 settings $settings = $config->settings; This provides a reference to the engine settings object from which you can interrogate various settings such as delimiters, etc. The full set of methods supported by the settings object is documented in L. =head2 default $text = $config->default; @lines = $config->default; This returns the text of the default configuration file embedded in the B<__DATA__> section of the config class. =head2 get $val = $config->get($parameter); @val = $config->get($parameter); %val = $config->get($parameter); This returns the store value(s) for the specified parameter. It is essentially the same as using the parent class L method, although this will not cause the program to L like L does. It will L, instead. =head2 set $rv = $config->set($parameter); $rv = $config->set($parameter, $newval); $rv = $config->set($parameter, @newval); $rv = $config->set($parameter, %newval); This method sets the desired parameter to the newly specified value(s). If no values are provided it will assume that you wish to set scalars to B or empty arrays and hashes. =head2 parse $rv = $config->parse($text); $rv = $config->parse(@lines); This will parse and set any parameters or prototypes found in the content. It will return false if any parsing errors are found (spurious text, etc.) but will extract everything of intelligible value it can. =head2 read $rv = $config->read($filename); $rv = $config->read(@files); $rv = $config->read($pglob); $rv = $config->read(*fh); This method will attempt to read every file passed to it, whether it be passed by file name, file handle, L, or objec reference support I/O functions. Fair warning: this does observe file locking semantics (L) and it will close any file handles passed to it after consuming the content. Also note that this method uses L, which implements protections against memory-utilization attacks. You may need to adjust the following parameters depending on the size of your config files: use Paranoid::IO qw(PIOMAXFSIZE PIOBLKSIZE); use Paranoid::IO qw(PIOMAXLNSIZE); # Adjust read block size for performance PIOBLKSIZE = 16 * 1024; # Allow file sizes up to 128KB PIOMAXFSIZE = 128 * 1024; # Allow individual lines to be 4KB long PIOMAXLNSIZE = 4 * 1024; =head2 reset $rv = $config->reset; This method emptys the contents of all parameters and prototypes, then applies the default settings as found in B<__DATA__>. =head2 prototyped @protos = $config->prototyped; @protos = $config->prototyped($preamble); This method returns a list of properties that were defined as the result of prototypes. With no arguments it returns all properties that were defined. With an argument it returns only those properties that were defined by that specific prototype preamble. =head2 error $errStr = $config->error; Returns the last error that occurred. Note that this isn't reset between method invocations. =head1 DEPENDENCIES =over =item o L =item o L =item o L =item o L =item o L =item o L =item o L =item o L =item o L =item o L =item o L =item o L =back =head1 DIAGNOSTICS Through the use of B this module will produce internal diagnostic output to STDERR. It begins logging at log level 6. To enable debugging output please see the pod for L. =head1 BUGS AND LIMITATIONS =head1 AUTHOR Arthur Corliss (corliss@digitalmages.com) =head1 LICENSE AND COPYRIGHT This software is licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information. (c) 2002 - 2023, Arthur Corliss (corliss@digitalmages.com) Parse-PlainConfig-3.07/INSTALL0000644000175000001440000000042712741127444015504 0ustar acorlissusersInstallation Instructions: ========================== If you have root access you can simply execute: perl Makefile.PL && make && make install If you're installing this in your own personal space use something akin to: perl Makefile.PL LIB=~/lib && make && make install Parse-PlainConfig-3.07/Makefile.PL0000644000175000001440000000131414502715446016423 0ustar acorlissusersuse ExtUtils::MakeMaker; use 5.008003; # Create the makefile WriteMakefile( NAME => 'Parse::PlainConfig', ABSTRACT => 'Parser/Generator of human-readable conf files', AUTHOR => 'Arthur Corliss ', VERSION_FROM => 'lib/Parse/PlainConfig.pm', PREREQ_PM => { 'Class::EHierarchy' => 2.00, 'Paranoid' => 2.10, 'Text::ParseWords' => 0, 'Text::Tabs' => 0, }, ( $ExtUtils::MakeMaker::VERSION ge '6.30_00' ? ( LICENSE => 'perl', ) : () ), ( $ExtUtils::MakeMaker::VERSION ge '6.48' ? ( MIN_PERL_VERSION => 5.008003 ) : () ), ); exit 0; Parse-PlainConfig-3.07/LICENSE0000644000175000001440000004737112741127444015471 0ustar acorlissusers Terms of Perl itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" ---------------------------------------------------------------------------- The General Public License (GPL) Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS ---------------------------------------------------------------------------- The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Parse-PlainConfig-3.07/README0000644000175000001440000000215112741127452015326 0ustar acorlissusersParse::PlainConfig ================== NOTICE: We've jumped a major rev due to a break in the API. After ten years of using Parse::PlainConfig it was inevitable that I would arrive to the conclusion that while the features was nice it was simply a major PITA from a developer's perspective. For that reason this module has been rewritten entirely from scratch with the aim to make it trivial to implement as a developer. I find the new subclassing method to be rather insanely easy, actually, and includes some new features. The trade off for that, however, was dropping the config generator, something that sounded good at the time, but something I never actually used. My wager is that no one else did, either. Legacy Support -------------- For your convenience I've left the old module in this distribution, albeit under new namespace. My hope is that this will require minimal adjustments to any existing scripts that rely on it. I truly believe, though, you will find the new version so much more pleasureable to use that you'll migrate to that, instead. The old module is now called Parse::PlainConfig::Legacy. Parse-PlainConfig-3.07/META.yml0000640000175000001440000000112514547616507015725 0ustar acorlissusers--- abstract: 'Parser/Generator of human-readable conf files' author: - 'Arthur Corliss ' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.86, CPAN::Meta::Converter version 2.120351' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Parse-PlainConfig no_index: directory: - t - inc requires: Class::EHierarchy: 2 Paranoid: 2.1 Text::ParseWords: 0 Text::Tabs: 0 perl: 5.008003 version: 3.07 Parse-PlainConfig-3.07/META.json0000640000175000001440000000203114547616507016072 0ustar acorlissusers{ "abstract" : "Parser/Generator of human-readable conf files", "author" : [ "Arthur Corliss " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.86, CPAN::Meta::Converter version 2.120351", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Parse-PlainConfig", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Class::EHierarchy" : "2", "Paranoid" : "2.1", "Text::ParseWords" : "0", "Text::Tabs" : "0", "perl" : "5.008003" } } }, "release_status" : "stable", "version" : "3.07" }