moved flags to the container
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / Container.pm
index f8a9e97..9a9137c 100644 (file)
@@ -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,9 @@ sub BUILD {
         config_local_suffix
         config_path
         locate_components
+        flags
+        home
+        root_dir
     /;
 
     my $config = $self->resolve( service => 'config' );
@@ -145,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;
 
@@ -152,18 +191,20 @@ sub build_home_service {
         lifecycle => 'Singleton',
         name => 'home',
         block => sub {
-            my $self = shift;
+            my $self  = shift;
             my $class = $self->param('catalyst_application');
-            my $home;
 
             if ( my $env = Catalyst::Utils::env_value( $class, 'HOME' ) ) {
-                $home = $env;
+                return $env;
             }
 
-            $home ||= Catalyst::Utils::home($class);
-            return $home;
+            if ( my $home = $self->param('flags')->{home} ) {
+                return $home;
+            }
+
+            return Catalyst::Utils::home($class);
         },
-        dependencies => [ depends_on('catalyst_application') ],
+        dependencies => [ depends_on('flags'), depends_on('catalyst_application') ],
     );
 }
 
@@ -805,6 +846,17 @@ Same as L<build_model_subcontainer>, but for controllers.
 
 Name of the application (such as MyApp).
 
+=head2 build_home_service
+
+The application home directory. All the files (including classes, scripts, etc)
+created for this application are in this directory, or in a sub-directory below
+this one.
+
+=head2 build_root_dir_service
+
+Inside the application home (as explained in L</build_home_service>), there is
+a root directory. This is where all templates and static files are.
+
 =head2 build_driver_service
 
 Config options passed directly to the driver being used.