Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7659187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:18:00+00:00 2026-05-31T13:18:00+00:00

i’d like to be able to create ghost packages and subs. I have a

  • 0

i’d like to be able to create “ghost” packages and subs. I have a configuration (ini) file with entries like this:

[features]
sys.ext.latex = off
gui.super.duper.elastic = off
user.login.rsa = on

This file is parsed, and later developers can ask questions like:

if ( MyApp::Feature->enabled ( 'user.login.rsa' ) { ... }

(The whole idea is based on Martin Fowler’s FeatureToggle http://martinfowler.com/bliki/FeatureToggle.html)

Using AUTOLOAD for catching calls in MyApp::Feature, and BEGIN block for parsing ini file we are able to provide this API:

if ( MyApp::Feature->user_login_rsa ) { ... }

The question is: Is it possible to create following API:

if ( MyApp::Feature::User::Login::RSA ) { ... }

having only MyApp::Feature?

Lower,upper case can be modified in the config file, that’s not the issue here. And make it clear, implementation is decoupled from the configuration, there is no MyApp::Feature::User::Login::RSA and never will be. Implementation for this feature lies f.e. in MyApp::Humans.

I am aware that putting MyApp::Feature::Foo::Bar suggests there must be such Package. But developers know the convention that Feature package manages feature toggles and they would have no problems with that. I find the first example (using enabled( $string ) bit too complex to read

if ( package::package->method ( string ) )

the second one better:

if ( package::package->method )

the third would be even easier:

if ( package::package::package )

So, is it possible to simulate AUTOLOAD on the package level?

Greetings,
Rob.


  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:18:01+00:00Added an answer on May 31, 2026 at 1:18 pm

    So it sounds like you have a list of multi-word keys that you want to install into a namespace.

    BEGIN {
        my %states = ( # the values that should be transformed
            on  => sub () {1},
            off => sub () {''},
        );
        sub install_config {
            my ($package, $config) = @_;
            for my $key (keys %$config) {
                my @parts = map ucfirst, split /\./, $key;
                my $name  = join '::' => $package, @parts;
                no strict 'refs';
                *{$name} = $states{$$config{$key}} # use a tranformed value
                        || sub () {$$config{$key}} # or the value itself
            }
        }
    }
    
    BEGIN {
        my %config = qw(
            sys.ext.latex            off
            gui.super.duper.elastic  off
            user.login.rsa           on
            some.other.config        other_value
        );
        install_config 'MyApp::Feature' => \%config;
    }
    
    say MyApp::Feature::Sys::Ext::Latex ? 'ON' : 'OFF';             # OFF
    say MyApp::Feature::Gui::Super::Duper::Elastic ? 'ON' : 'OFF';  # OFF
    say MyApp::Feature::User::Login::Rsa ? 'ON' : 'OFF';            # ON
    say MyApp::Feature::Some::Other::Config;                        # other_value
    

    The constant subroutines installed here are will be inlined by perl when applicable.

    You can make install_config a bit easier to use by putting it into a package’s import function:

    BEGIN {$INC{'Install/Config.pm'}++} # fool require
    
    sub Install::Config::import {shift; goto &install_config}
    
    use Install::Config 'MyApp::Feature' => {qw(
        sys.ext.latex            off
        gui.super.duper.elastic  off
        user.login.rsa           on
        some.other.config        other_value
    )};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a reasonable size flat file database of text documents mostly saved in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.