« blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/App/Model/Email.pm
↑ Summary
blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Util.pm »
| 1 | package Dwarf::Plugin::MultiConfig; | ||
| 2 | use Dwarf::Pragma; | ||
| 3 | use Dwarf::Util qw/add_method load_class/; | ||
| 4 | use Sys::Hostname; | ||
| 5 | |||
| 6 | sub init { | ||
| 7 | my ($class, $c, $conf) = @_; | ||
| 8 | $conf ||= {}; | ||
| 9 | |||
| 10 | my $production = $conf->{production} || 'production'; | ||
| 11 | my $developments = $conf->{development} || {}; | ||
| 12 | |||
| 13 | add_method($c, hostname => sub { | ||
| 14 | Sys::Hostname::hostname(); | ||
| 15 | }); | ||
| 16 | |||
| 17 | add_method($c, config_name => sub { | ||
| 18 | my $self = shift; | ||
| 19 | |||
| 20 | $self->{'dwarf.config'} ||= do { | ||
| 21 | my $name = $production; | ||
| 22 | my @def = @$developments; | ||
| 23 | |||
| 24 | for (my $i = 0; $i < @def; $i = $i + 2) { | ||
| 25 | my $key = $def[$i]; | ||
| 26 | my $value = $def[$i + 1]; | ||
| 27 | |||
| 28 | my ($host, $dir); | ||
| 29 | if (ref $value eq 'HASH') { | ||
| 30 | $host = $value->{host}; | ||
| 31 | $dir = $value->{dir}; | ||
| 32 | } else { | ||
| 33 | $host = $value; | ||
| 34 | } | ||
| 35 | |||
| 36 | if ($self->hostname =~ /$host/) { | ||
| 37 | if ($dir) { | ||
| 38 | if ($self->base_dir =~ /$dir/) { | ||
| 39 | $name = $key; | ||
| 40 | last; | ||
| 41 | } | ||
| 42 | } else { | ||
| 43 | $name = $key; | ||
| 44 | last; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | $name; | ||
| 50 | }; | ||
| 51 | }); | ||
| 52 | |||
| 53 | add_method($c, is_production => sub { | ||
| 54 | shift->config_name eq $production; | ||
| 55 | }); | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; |