in reply to Config::Std to lexical in BEGIN { } throws warning?

I believe that %config goes out of scope at the end of the BEGIN block. When the BEGIN block completes, DEMOLISH is able to be called, because %config has just gone out of scope. Now, whenever you are using %config in the rest of your application, I am not certain where the data is coming from.

If you move my %config outside of the BEGIN block, and then change the read_config line to read_config "main.conf" => %config, it should take care if the problems, and you will actually have the data from your configuration file used by the application.

This would have been told you if you had done a use strict; use warnings; before the BEGIN block.

It is said that "only perl can parse Perl." I don't even come close until my 3rd cup of coffee. --MidLifeXis

Replies are listed 'Best First'.
Re^2: Config::Std to lexial in BEGIN { } throws warning?
by gorash (Novice) on Feb 23, 2010 at 17:23 UTC

    Updated origial post to reflect MidLifeXis post.

    Unfortunately, I cannot move the my outside, because the code never gets a chance on that with RDBO. Just useing a model runs most of it immediately.

      So this does not do what you want it to?

      use Config::Std; my %config; BEGIN { read_config "main.conf" => %config; }

      It is said that "only perl can parse Perl." I don't even come close until my 3rd cup of coffee. --MidLifeXis

        Oh, the original code does what I want it to do already. Unfortunately the warning pops up. Your version circumvents the warning, but in a way that is not helpful to me, because it cannot be applied to the real code. A little less compact version of the actual code would be:

        package Get::Me::My::Config; use Config::Std; sub get_config { read_config _file_name() => my %config; return \%config; } package Database::Stuff; use base q(Rose::DB); use Get::Me::My::Config; sub init_db { my $db_conf = Get::Me::My::Config->get_config->{db_conf}; return _create_db_from($db_conf); }
        Something like this. Now to apply your changes, I would need to change the lexical into a package global, which simply is not what I intended for this variable to be at this place.