From: André Walker Date: Thu, 26 Jul 2012 02:50:23 +0000 (-0300) Subject: moved flags to the container X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=d9a59c532eec44e3c85a44566a2e1afbb0c22c93 moved flags to the container --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 0e01305..4d3add3 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -137,7 +137,7 @@ sub import { # we call setup_home on import AND on ->setup # is there a reason for it? # anyway there is no point for setup_home without setup_config() so... - $caller->setup_config; + $caller->setup_config($caller->arguments); $caller->setup_home; } @@ -919,25 +919,9 @@ sub setup { @arguments = ( @arguments, @{ $class->arguments } ); } - # Process options - my $flags = {}; - - foreach (@arguments) { - - if (/^-Debug$/) { - $flags->{log} = - ( $flags->{log} ) ? 'debug,' . $flags->{log} : 'debug'; - } - elsif (/^-(\w+)=?(.*)$/) { - $flags->{ lc $1 } = $2; - } - else { - push @{ $flags->{plugins} }, $_; - } - } - - $class->setup_config(); - $class->setup_home( delete $flags->{home} ); + $class->setup_config(\@arguments); + my $flags = $class->container->resolve(service => 'flags'); + $class->setup_home(); $class->setup_log( delete $flags->{log} ); $class->setup_plugins( delete $flags->{plugins} ); @@ -2332,7 +2316,7 @@ sub setup_actions { my $c = shift; $c->dispatcher->setup_actions( $c, @_ ) } =cut sub setup_config { - my $class = shift; + my ($class, $flags) = @_; my %args = %{ $class->config || {} }; @@ -2346,7 +2330,7 @@ sub setup_config { $container_class = Class::MOP::load_first_existing_class("${class}::Container", 'Catalyst::IOC::Container'); } - my $container = $container_class->new( %args, name => $class ); + my $container = $container_class->new( %args, name => $class, flags => $flags ); $class->container($container); my $config = $container->resolve( service => 'config' ); @@ -2606,13 +2590,10 @@ Sets up the home directory. =cut sub setup_home { - my ( $class, $home_flag ) = @_; + my ( $class ) = @_; my $home = $class->container->resolve( service => 'home', - parameters => { - home_flag => $home_flag - }, ); if ($home) { diff --git a/lib/Catalyst/IOC/Container.pm b/lib/Catalyst/IOC/Container.pm index cb82f69..9a9137c 100644 --- a/lib/Catalyst/IOC/Container.pm +++ b/lib/Catalyst/IOC/Container.pm @@ -17,6 +17,12 @@ use namespace::autoclean; extends 'Bread::Board::Container'; +has flags => ( + is => 'ro', + isa => 'ArrayRef', + default => sub { [] }, +); + has config_local_suffix => ( is => 'ro', isa => 'Str', @@ -74,6 +80,7 @@ sub BUILD { config_local_suffix config_path locate_components + flags home root_dir /; @@ -147,6 +154,36 @@ sub build_component_subcontainer { ); } +sub build_flags_service { + my $self = shift; + + return Bread::Board::Literal->new( + lifecycle => 'Singleton', + name => 'flags', + value => $self->get_flags, + ); +} + +sub get_flags { + my $self = shift; + my $flags = {}; + + foreach (@{ $self->flags }) { + if (/^-Debug$/) { + $flags->{log} = + ( $flags->{log} ) ? 'debug,' . $flags->{log} : 'debug'; + } + elsif (/^-(\w+)=?(.*)$/) { + $flags->{ lc $1 } = $2; + } + else { + push @{ $flags->{plugins} }, $_; + } + } + + return $flags; +} + sub build_home_service { my $self = shift; @@ -161,16 +198,13 @@ sub build_home_service { return $env; } - if ( my $home = $self->param('home_flag') ) { + if ( my $home = $self->param('flags')->{home} ) { return $home; } return Catalyst::Utils::home($class); }, - parameters => { - home_flag => { is => 'ro', isa => 'Str|Undef', required => 0 } - }, - dependencies => [ depends_on('catalyst_application') ], + dependencies => [ depends_on('flags'), depends_on('catalyst_application') ], ); }