Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Bricolage: devel
Re: Config Constants and Testing
 

Index | Next | Previous | View Flat


catalyst at mikeraynham

Jun 11, 2011, 11:34 AM


Views: 2655
Permalink
Re: Config Constants and Testing [In reply to]

On 11/06/11 18:38, David E. Wheeler wrote:
> On Jun 10, 2011, at 8:40 PM, Mike Raynham wrote:
>
>> Would you be happy for me to submit a patch for Bric::Config so that
>> configuration directives can be obtained via an AUTOLOAD getter method?
>>
>> Configuration directives can then be migrated as and when required.
>
> No autoload, please.
>
> We could maybe set something up, though, so that they get created as functions rather than constants. Then you could replace them at runtime using Test::MockModule.

My plan is to create an AUTOLOAD function in Bric::Config which will
replace each of the constants with a getter function. I've attached a
diff of the Bric::Config code that I've been experimenting with so far.


if (MEDIA_UNIQUE_FILENAME) { ... }

would be replaced with:

if (Bric::Config::get_media_unique_filename) { ... }


The functions could be exported, but I thought it might be clearer (if a
little longer) to use the fully qualified name.

As there are lots of constants throughout the code, they can be switched
out as and when required, rather than all at once. The AUTOLOAD
function throws an exception if the configuration directive is defined
as a constant, so it shouldn't be possible to use both at the same time.

Many of the constants can simply be removed or commented out, and they
will automatically be available via a getter function. In some cases,
default values are set at the point at which the constant is created.
In these cases, the $config hash value will need setting or updating as
appropriate. For example:

use constant MEDIA_URI_ROOT => '/data/media';

would have to be changed to:

$config->{MEDIA_URI_ROOT} = '/data/media';

The functions created by AUTOLOAD can then be overridden with
Test::MockModule.

Is this what you were thinking?

I've started a DevTest module for Bric::Config too. At the moment it
just checks that AUTOLOAD throws the correct exceptions. I'm sure it
could be enhanced later.



Regards,

Mike
Attachments: config.git.tar.gz (1.34 KB)

Subject User Time
Config Constants and Testing catalyst at mikeraynham Jun 10, 2011, 8:27 AM
    Re: Config Constants and Testing david at kineticode Jun 10, 2011, 3:01 PM
    Re: Config Constants and Testing catalyst at mikeraynham Jun 10, 2011, 8:40 PM
        Re: Config Constants and Testing david at kineticode Jun 11, 2011, 10:38 AM
    Re: Config Constants and Testing catalyst at mikeraynham Jun 11, 2011, 11:34 AM
        Re: Config Constants and Testing david at kineticode Jun 11, 2011, 1:24 PM
    Re: Config Constants and Testing catalyst at mikeraynham Jun 11, 2011, 2:15 PM
        Re: Config Constants and Testing david at kineticode Jun 11, 2011, 7:56 PM
    Re: Config Constants and Testing catalyst at mikeraynham Jun 12, 2011, 12:44 AM
        Re: Config Constants and Testing david at kineticode Jun 12, 2011, 9:20 AM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.