Skip Menu |

This queue is for tickets about the Config-General CPAN distribution.

Report information
The Basics
Id: 79694
Status: resolved
Priority: 0/
Queue: Config-General

People
Owner: Nobody in particular
Requestors: burak [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: An interface to skip non-existing or non-readable includes (fine control/tuning)
Hi, I'd like to be able to do this[1] to skip some random number of included files. Basically we can have lets say 10 includes in a conf file and some of them might suddenly disappear by some automated tool failure or sysadmin error. But 80% of the code can run in some degraded mode without (lets say) half of the files present. I'm not so sure about the interface but perhaps it can be something like: if ( $this->{missing_include_handler} && defined $this->{missing_include_handler}->( $configfile ) # can also die() or whatever # or make this $this->missing_include_handler which can be overridden by a subclass ) { return; } # fall back to the default: die() Additionally, if the call to actual open (CORE::open) can be hidden in a single method as well, it'll be good to have that over ridable. Currently the calls to open are not limited to a single abstracted call (I'd like to have this to be able to detect the file modes and ignore them if they exist but not readable and lets say $IGNORABLE{ $file } is true). Thanks, Burak ----------[1]------------ [burak@foo Config]$ diff -uNa General.pm.orig General.pm --- General.pm.orig 2012-09-17 17:36:08.000000000 +0200 +++ General.pm 2012-09-17 17:38:29.000000000 +0200 @@ -462,6 +462,10 @@ } } if (!$found) { + if ( $configfile =~ m{foobar[.]conf$} ) { + warn "oooh! nooooes! -> $configfile\n"; + return; + } my $path_message = defined $this->{ConfigPath} ? q( within ConfigPath: ) . join(q(.), @ {$this->{ConfigPath}}) : q(); croak qq{Config::General The file "$basefile" does not exist$path_message!}; }
Well. Now I started to add some kind of plugin interface to the module. This way one could change the modules behavior in any way. This would solve your problem as well, I think. Here's some first shot at it: #!/usr/bin/perl use lib qw(blib/lib); use Config::General qw(ParseConfig); use Data::Dumper; sub ck { my($file, $base) = @_; print "_open() tries $file ... "; if($file =~ /blah/) { print "ignored\n"; return (0); } else { print "allowed\n"; return (1, @_); } } my %c = ParseConfig( -IncludeGlob => 1, -UseApacheInclude => 1, -ConfigFile => shift, -Plug => { pre_open => *ck } ); print Dumper(\%c); Output: _open() tries cfg ... allowed _open() tries x/*.conf ... allowed _open() tries x/1.conf ... allowed _open() tries x/2.conf ... allowed _open() tries x/blah.conf ... ignored $VAR1 = { 'niemand' => '2', 'hallo' => '1' }; However, I'll need some time to figure out which are the best places for hooks to add. But you'll get the picture.
10 Eki 2012 Çrş, 16:12:04 tarihinde, TLINDEN yazdı: Show quoted text
> Well. Now I started to add some kind of plugin interface to the module. > This way one could change the modules behavior in any way. This would > solve your problem as well, I think. > > Here's some first shot at it:
Thanks. That's indeed what I need :) Show quoted text
> #!/usr/bin/perl > use lib qw(blib/lib); > use Config::General qw(ParseConfig); > use Data::Dumper; > > sub ck { > my($file, $base) = @_; > print "_open() tries $file ... "; > if($file =~ /blah/) { > print "ignored\n"; > return (0); > } > else { > print "allowed\n"; > return (1, @_); > } > } > > my %c = ParseConfig( > -IncludeGlob => 1, > -UseApacheInclude => 1, > -ConfigFile => shift, > -Plug => { pre_open => *ck } > ); > > print Dumper(\%c); > > > > Output: > _open() tries cfg ... allowed > _open() tries x/*.conf ... allowed > _open() tries x/1.conf ... allowed > _open() tries x/2.conf ... allowed > _open() tries x/blah.conf ... ignored > $VAR1 = { > 'niemand' => '2', > 'hallo' => '1' > }; > > > However, I'll need some time to figure out which are the best places for > hooks to add. But you'll get the picture.
I close the case. I added the feature officially in 2.52. The following hooks are available as of now: pre_open pre_read post_read pre_parse_value post_parse_value Thanks for the hint!
03 Tem 2013 Çrş, 04:26:32 tarihinde, TLINDEN yazdı: Show quoted text
> I close the case. I added the feature officially in 2.52. The > following hooks are available as of now: > > pre_open > pre_read > post_read > pre_parse_value > post_parse_value > > Thanks for the hint!
Thanks for implementing it :)