namespaces - Perl: Setup multiple package names for variable/functions? -


first, i'd isn't question of design, question of compliance. i'm aware there issues current setup.

in module, there packages named after servers, has many of same variables/functions pertain server. looks set do:

  • production_server_name::printer() or
    test_server_name::printer()

perhaps better design might have been like:

  • central_package_name::printer('production') or central_package_name::printer('test')

anyhow, seems server names have changed, instead of using actual servernames, i'd rename packages production or test, without changing other code still refering production_server_name.

something like:

package production, production_server_name;  # pseudo code 

i'm guessing sort of glob/import might work, wondering if there something similar. realize it's not practice saturate namespaces.

i not providing comments on design or might involve changing client code. functions in mytest.pm can accessed using either mytest:: or myexam::. however, can't use use myexam because physical file not there. clever @inc tricks, programs crash , burn when try clever.

mytest.pm

package mytest;  sub hello { 'hello' } sub twoplustwo { 4 }  $sub (qw( hello twoplustwo)) {     no strict 'refs';     *{"myexam::$sub"} = *{"mytest::$sub"}; }  1; 

test.pl

#!/usr/bin/env perl  use strict; use warnings; use feature 'say';  use mytest;  myexam::hello(); myexam::twoplustwo(); 

output:

hello 4

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -