Permalink
Browse files

change configuration with env

  • Loading branch information...
1 parent f13b65e commit d8bd4209065b51f438712c9e0691f2b384db259e @dann committed Feb 27, 2009
View
@@ -30,10 +30,12 @@ all_from 'lib/Angelos.pm';
requires(
# Basics
- 'Mouse' => '0.16',
+ 'Class::Method::Modifiers' => 0,
+ 'Class::Method::Modifiers::Fast' => 0,
+ 'Mouse' => '0.17',
'MouseX::Types' => '0.01',
- 'HTTP::Engine' => '0.1.3',
- 'HTTP::Engine::Middleware' => '0.04',
+ 'HTTP::Engine' => '0.1.4',
+ 'HTTP::Engine::Middleware' => '0.09',
'HTTP::Router' => 0,
'HTTP::Session' => 0,
'Module::Pluggable::Object' => 0,
@@ -50,8 +52,7 @@ requires(
'IO::Pager' => 0,
'Params::Validate' => 0,
'Data::Util' => 0,
- 'Class::Method::Modifiers::Fast' => 0,
- 'Class::Singleton' => 0,
+ 'Class::Singleton' => 0,
# Config
'Kwalify' => 0,
@@ -62,7 +63,7 @@ requires(
'Pod::Simple::Text' => 0,
'MouseX::Getopt' => '0.04',
'IPC::System::Simple' => 0,
- 'App::Cmd' => 0,
+ 'App::Cmd' => '0.202',
'Module::Setup' => 0,
'FindBin::libs' => 0,
'File::Slurp' => 0,
@@ -86,6 +87,11 @@ requires(
'HTML::FillInForm' => 0,
'FormValidator::Simple' => 0,
+ # testing
+ 'HTTP::Request::Common' => 0,
+ 'Test::Class' => 0,
+ 'Test::Base' => 0,
+
# View Plugins (remove from core)
# Middleware
@@ -105,10 +111,11 @@ else {
}
test_requires(
+ 'Test::LoadAllModules' => 0,
'Test::Most' => 0,
+ 'Test::Class' => 0,
'Test::Exception' => 0,
'Test::MockObject' => 0,
- 'Test::Class' => 0,
'Test::TCP' => 0,
'LWP::UserAgent' => 0,
'Module::Load::Conditional' => 0,
@@ -0,0 +1,18 @@
+--- !ditz.rubyforge.org,2008-03-06/issue
+title: Implement the feature to use some plugins when debug mode is enabled
+desc: ""
+type: :task
+component: angelos
+release: "0.01"
+reporter: dann <techmemo@gmail.com>
+status: :unstarted
+disposition:
+creation_time: 2009-02-15 16:10:38.689082 Z
+references: []
+
+id: 36feb978801e763fa1916bdb44b0abd045b7e13d
+log_events:
+- - 2009-02-15 16:10:39.488476 Z
+ - dann <techmemo@gmail.com>
+ - created
+ - ""
@@ -0,0 +1,22 @@
+--- !ditz.rubyforge.org,2008-03-06/issue
+title: "MyApp::Config\xE3\x81\xAEgenerate. \xE3\x82\xA4\xE3\x83\xB3\xE3\x82\xB9\xE3\x82\xBF\xE3\x83\xB3\xE3\x82\xB9\xE3\x82\x92\xE4\xB8\x8A\xE6\x9B\xB8\xE3\x81\x8D\xE3\x81\x99\xE3\x82\x8B\xE4\xBB\x95\xE7\xB5\x84\xE3\x81\xBF\xE3\x81\xAF\xE7\x94\xA8\xE6\x84\x8F"
+desc: ""
+type: :task
+component: angelos
+release: "0.01"
+reporter: dann <techmemo@gmail.com>
+status: :closed
+disposition: :fixed
+creation_time: 2009-02-27 05:39:40.510069 Z
+references: []
+
+id: b7d8b6f52c4694d3ba516ec566d24071b8aca286
+log_events:
+- - 2009-02-27 05:39:41.606160 Z
+ - dann <techmemo@gmail.com>
+ - created
+ - ""
+- - 2009-02-27 06:13:03.433038 Z
+ - dann <techmemo@gmail.com>
+ - closed with disposition fixed
+ - ""
@@ -0,0 +1,18 @@
+--- !ditz.rubyforge.org,2008-03-06/issue
+title: "ModPerl\xE3\x81\xA7\xE3\x81\xAE\xE3\x82\xA2\xE3\x83\x97\xE3\x83\xAA\xE3\x82\xB1\xE3\x83\xBC\xE3\x82\xB7\xE3\x83\xA7\xE3\x83\xB3\xE5\x90\x8D\xE3\x81\xAE\xE6\xB8\xA1\xE3\x81\x97\xE6\x96\xB9"
+desc: ""
+type: :task
+component: angelos
+release: "0.01"
+reporter: dann <techmemo@gmail.com>
+status: :unstarted
+disposition:
+creation_time: 2009-02-27 06:13:41.882829 Z
+references: []
+
+id: e48e6ef8a6a5cd223a470c277f0cdb77e9a30b7d
+log_events:
+- - 2009-02-27 06:13:42.242258 Z
+ - dann <techmemo@gmail.com>
+ - created
+ - ""
@@ -1,5 +1,5 @@
package Angelos;
-use 5.00800;
+use 5.008_001;
our $VERSION = '0.01';
use Angelos::Class;
use Angelos::MIMETypes;
@@ -61,9 +61,15 @@ has 'engine' => (
[qw(controller model view forward detach full_forward full_detach)],
);
-has 'config' => ( is => 'rw', );
+has 'config' => (
+ is => 'rw',
+ isa => 'Angelos::Config'
+);
-has 'logger' => ( is => 'rw', );
+has 'logger' => (
+ is => 'rw',
+ isa => 'Angelos::Logger'
+);
has 'localizer' => ( is => 'rw', );
@@ -101,6 +107,11 @@ has '_match' => ( is => 'rw', );
# This attribute is used for test only
has 'request_handler' => ( is => 'rw', );
+has 'env' => (
+ is => 'rw',
+ isa => 'Str',
+);
+
sub BUILD {
my $self = shift;
$self->setup;
@@ -149,21 +160,31 @@ sub create_home {
sub setup_config {
my $self = shift;
my $config = $self->create_config;
- $self->config($config);
+ $self->config($config) if $config;
$config;
}
sub create_config {
my $self = shift;
my $config_class = join '::', ( ref $self, 'Config' );
$config_class->require;
- $config_class->instance;
+ $config_class->instance( $self->environment );
+}
+
+sub environment {
+ my $self = shift;
+ my $environment;
+ $environment ||= $ENV{ANGELOS_ENV};
+ $environment ||= Angelos::Utils::env_value( ref $self, 'ENV' );
+ $environment ||= 'development' if $ENV{ANGELOS_DEBUG};
+ $environment ||= 'production';
+ $environment;
}
sub setup_logger {
my $self = shift;
my $logger = $self->create_logger;
- $self->logger($logger);
+ $self->logger($logger) if $logger;
$logger;
}
@@ -177,7 +198,7 @@ sub create_logger {
sub setup_localizer {
my $self = shift;
my $localizer = $self->create_localizer;
- $self->localizer($localizer);
+ $self->localizer($localizer) if $localizer;
$localizer;
}
@@ -9,15 +9,14 @@ use base 'Class::Singleton';
sub _new_instance {
my $class = shift;
my $self = bless {}, $class;
- my $config_file = shift;
- # Angelos::Utils::context()->project_structure->config_file;
- $self->{config} = Angelos::Config::Loader->load( $config_file || $self->config_file ,
+ $self->{config} = Angelos::Config::Loader->load( $self->config_file ,
Angelos::Config::Schema->config );
return $self;
}
sub config_file {
+ my ($self, $environment) = @_;
Angelos::Exception::AbstractMethod->throw(
message => 'Sub class must implement config_file method'
);
@@ -1,8 +1,8 @@
package Angelos::ProjectStructure;
use Angelos::Class;
-has 'home' => (
- is => 'rw',
+has 'home' => (
+ is => 'rw',
isa => 'Angelos::Home',
);
@@ -17,8 +17,10 @@ sub routes_config_file {
}
sub config_file {
- my $self = shift;
- $self->home->path_to( 'conf', 'config.yaml' ),;
+ my ( $self, $environment ) = @_;
+ my $extension = '.yaml';
+ my $config_filename = $environment . $extension;
+ $self->home->path_to( 'conf', 'environments', $config_filename ),;
}
sub root_dir {
@@ -102,16 +102,6 @@ template: |
auto_include;
WriteAll;
---
-file: conf/config.yaml
-template: |
- ---
- components:
- controller:
- - module: A
-
- middlewares:
- - module: Encode
----
file: conf/routes.pl
template: |+
HTTP::Router->define(
@@ -142,6 +132,40 @@ template: |
text: yellow
background: red
---
+file: conf/environments/production.yaml
+template: |
+ ---
+ components:
+ controller:
+ - module: A
+
+ middlewares:
+ - module: Encode
+---
+file: conf/environments/testing.yaml
+template: |
+ ---
+ components:
+ controller:
+ - module: A
+
+ middlewares:
+ - module: Encode
+---
+file: conf/environments/development.yaml
+template: |+
+ ---
+ components:
+ controller:
+ - module: A
+
+ middlewares:
+ - module: DebugScreen
+ - module: Static
+ - module: DebugRequest
+ - module: Encode
+
+---
file: lib/____var-module_path-var____.pm
template: |
package [% module %];
@@ -193,8 +217,9 @@ template: |
use Angelos::ProjectStructure;
sub config_file {
+ my $self = shift;
Angelos::ProjectStructure->new( home => [% module %]::Home->instance )
- ->config_file;
+ ->config_file($self->env);
}
1;
@@ -42,6 +42,12 @@ has 'help' => (
default => 0
);
+has 'env' => (
+ is => 'rw',
+ isa => 'Str',
+ default => 'development',
+);
+
sub run {
my $self = shift;
if ( $self->help ) {
@@ -1,19 +1,15 @@
use strict;
use warnings;
-use Test::More ();
-
-Test::More::plan('no_plan');
-
-use Module::Pluggable::Object;
-
-my $finder = Module::Pluggable::Object->new( search_path => ['Angelos'], );
-
-foreach my $class (
- grep !
- /\.ToDo|Angelos::Engine::ModPerl|Angelos::Component|HTPro|JobQueue|Angelos::Middleware::|Angelos::Plugin|Angelos::Role|Angelos::Test/,
- sort do { local @INC = ('lib'); $finder->plugins }
- )
-{
- Test::More::use_ok($class);
+use Test::LoadAllModules;
+
+BEGIN {
+ all_uses_ok(
+ search_path => 'Angelos',
+ except => [
+ 'Angelos::Engine::ModPerl', 'Angelos::Component',
+ 'Angelos::Middleware::.*', 'Angelos::Plugin',
+ 'Angelos::Test',
+ ]
+ );
}
@@ -0,0 +1,35 @@
+---
+components:
+ controller:
+ - module: A
+
+#plugins:
+# controller:
+# - module: ActionProfiler
+#
+# - module: DebugHook
+
+#mixins:
+# request:
+# - module: MobileAgent
+
+#middlewares:
+# - module: Static
+# - module: Encode
+
+# - module: DebugScreen
+# - module: DebugRequest
+# - module: Session
+
+# - module: Session
+# config:
+# store:
+# class: HTTP::Session::Store::File
+# config:
+# dir: /tmp/session
+# state:
+# class: HTTP::Session::State::URI
+# config:
+# session_id_name: hoge
+# id: HTTP::Session::ID::SHA1
+
Oops, something went wrong.

0 comments on commit d8bd420

Please sign in to comment.