Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Config::Tiny croaks at runtime, not in debugger

by haukex (Archbishop)
on May 06, 2016 at 15:12 UTC ( [id://1162364]=note: print w/replies, xml ) Need Help??


in reply to Config::Tiny croaks at runtime, not in debugger

Hi xavier8854,

Welcome!

What is the exact error message, including the contents of $Config::Tiny::errstr?

Also, I don't think chdir dirname($0); will be reliable in all environments, have a look at FindBin instead of trying to chdir (which may fail due to security/permission restrictions) or use $0 (which isn't always the name of the script file!). Even FindBin isn't always perfect but it tries fairly hard and has almost always worked for me.

use CGI::Carp qw/fatalsToBrowser/; use FindBin; use File::Spec::Functions qw/catfile/; use Config::Tiny; my $config = Config::Tiny->read(catfile($FindBin::Bin,'Config.ini')); croak "Failed to read Config.ini: $Config::Tiny::errstr" unless $confi +g;

Although you may want to consider the security implications of saving the config file alongside the script, and reporting the exact location of that file via the error message in case opening the file fails.

Regards,
-- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1162364]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-24 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found