Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
How is that possible? Sure you can redefine _, but that won't do any blessing at compile time.

Quite possible. My webapp is large, and runs within mod_perl, so I have an initialisation process which loads most required modules at the beginning. In my i18n class, which gets loaded as early as possible, I have this code:

{ no warnings 'redefine'; sub compile_mode { *::_ = sub { i18n::String->new(@_) }; } sub run_mode { *::_ = sub { $i18n::Current_Lang->maketext(@_) }; } } BEGIN { compile_mode(); }

Once initialisation is finished, my loader calls i18n::run_mode. If I need to require any large modules that belong to my app during runtime, instead of using the require builtin, I call i18n::i18n_require('Module::Name'):

sub i18n_require { my $original = my $path = shift; i18n::compile_mode(); $path=~s{::}{/}g; my $error; eval {require $path.'.pm'} or $error = $@ || 'Unknown error'; i18n::run_mode(); die( sprintf( "Error loading '%s' at %s line %d:\n%s\n", $original, (caller)[ 1, 2 ], $error ) ) if $error; return $INC{$path}; }

I tried overriding UNIVERSAL::require, but certain modules outside my control didn't appreciate that. Anyway, doing it this way is explicit, and only a few characters more.


In reply to Re^2: How do I pretend a reference isn't a reference by clinton
in thread How do I pretend a reference isn't a reference by clinton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2024-04-25 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found