Hi all,

I often come across situations where I need to create method names based
on an iterator of some sort, and I'm looking for feedback on whether
(ie. how) I can simplify the code, make it easier to read and make it
more scalable.

The ALL_CAPS are method names that are dynamically generated elsewhere
in the class from configuration file variables (using uc()). In this
case, I'm creating the connection information that will be used later
when creating a DBIx::Class::Schema.

The relevant snip of the config file:

[Database]
enable_replication      = 1
master_locked           = 0
slave_servers           = 2
master_source           = DBI:mysql:isp:master.example.com:
master_user             = isp
master_pass             = password
slave_1_source          = DBI:mysql:isp:slave1.example.com:
slave_1_user            = isp
slave_1_pass            = password
slave_2_source          = DBI:mysql:isp:slave1.example.com:
slave_2_user            = isp
slave_2_pass            = password

...and the associated code snip:

    # ...and add any slaves

    if ( $self->ENABLE_REPLICATION() && $self->SLAVE_SERVERS() ){

        for my $slave_number ( 1 .. $self->SLAVE_SERVERS() ){

            my $slave_info = "SLAVE_${ slave_number }_";

            my $slave; # aref

            for my $item ( qw/ SOURCE USER PASS / ){

                my $function = $slave_info . $item;

                push @$slave, $self->$function();
            }

            push @$database_servers, $slave;
        }
    }

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to