Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added schema loader

  • Loading branch information...
commit f5f55e50063fcd31a8ac0390b3dc14c32bb35541 1 parent 7242b82
@dann authored
View
8 angelos-core/bugs/issue-b5bed8f1f1b527d28ce1353c722abf0c48429eb1.yaml
@@ -5,8 +5,8 @@ type: :task
component: script
release: "0.01"
reporter: dann <techmemo@gmail.com>
-status: :unstarted
-disposition:
+status: :closed
+disposition: :fixed
creation_time: 2009-02-28 03:06:36.647016 Z
references: []
@@ -16,3 +16,7 @@ log_events:
- dann <techmemo@gmail.com>
- created
- ""
+- - 2009-04-19 01:07:11.545396 Z
+ - dann <techmemo@gmail.com>
+ - closed with disposition fixed
+ - ""
View
25 angelos-core/flavors/flavors/app/template/lib/____var-module_path-var____/Schema.pm
@@ -1,27 +1,4 @@
package [% module %]::Schema;
-use Mouse;
-use [% module %]::Config;
-extends qw(DBIx::Class::Schema);
+use base qw(Angelos::ORM::DBIC::Schema);
-sub master {
- my $class = shift;
- my $connect_info = $class->config->{'Model::DBIC'}{'connect_info'};
- my $schema = $class->connect( @{$connect_info} );
- return $schema;
-}
-
-sub slave {
- my $class = shift;
- return unless $class->config->{'Model::DBIC::Slave'};
- my $connect_info = $class->config->{'Model::DBIC::Slave'}{'connect_info'};
- my $schema = $class->connect( @{$connect_info} );
- return $schema;
-}
-
-sub config {
- [% module %]::Config->instance;
-}
-
-no Mouse;
-__PACKAGE__->meta->make_immutable;
1;
View
7 angelos-core/lib/Angelos/Engine/Base.pm
@@ -79,6 +79,7 @@ sub build_engine {
);
}
+
sub build_request_handler {
my $self = shift;
@@ -88,8 +89,14 @@ sub build_request_handler {
my $req = shift;
my $res = HTTP::Engine::Response->new;
my $c = $self->create_context( $req, $res );
+
+ use Devel::MemUsed;
+ my $memused = Devel::MemUsed->new;
+
no warnings 'redefine';
local *Angelos::Registrar::context = sub {$c};
+
+ $self->log->info(sprintf( "MEMORY: %08s", $memused ) . "\n");
$request_handler->($req);
};
$request_handler_with_context;
View
37 angelos-core/lib/Angelos/Script/Command/Db.pm
@@ -4,6 +4,7 @@ use warnings;
use base qw(Angelos::Script::Command);
use Carp ();
use Path::Class;
+use Mouse;
use DBIx::Class::Schema::Loader qw/make_schema_at/;
use lib 'lib';
@@ -13,8 +14,11 @@ Angelos::Script::Command::Db - db command
=head1 DESCRIPTION
- % angelos db --setup
- % angelos db --generate_schema --app_class MyApp
+ Setup database
+ % angelos db --setup
+
+ Generate Schema
+ % angelos db --gen --app_class MyApp
=head1 METHODS
@@ -25,7 +29,7 @@ Angelos::Script::Command::Db - db command
sub opt_spec {
return (
[ "setup", "create database?" ],
- [ "generate_schema", "generate schema?" ],
+ [ "gen", "generate schema?" ],
[ "app_class=s", "app_class" ],
);
}
@@ -37,7 +41,9 @@ sub validate_args {
sub run {
my ( $self, $opt, $arg ) = @_;
- $self->generate_schema($opt) if $opt->{'generate_schema'};
+ #FIXME move to base class
+ $self->setup_context($opt->{app_class});
+ $self->generate_schema($opt) if $opt->{'gen'};
$self->setup_database($opt) if $opt->{'setup'};
}
@@ -47,13 +53,12 @@ sub generate_schema {
Carp::croak 'app_class option must be set to generate schema'
unless $app_class;
- my $erase = $opt->{erase} || 0;
my $connect_info = $self->_get_connect_info($app_class);
make_schema_at(
"${app_class}::Schema",
{ components => [ ],
dump_directory => dir( 'lib' ),
- really_erase_my_files => $erase,
+ really_erase_my_files => 1,
debug => 1,
},
$connect_info,
@@ -84,4 +89,24 @@ sub _create_config {
$config_class->instance;
}
+# FIXME refactor context from app and create context class or remove context
+# class
+sub _create_app {
+ my ($self, $app_class) = @_;
+ Mouse::load_class($app_class);
+ my $app = $app_class->new(
+ host => 'localhost',
+ port => '3001',
+ server => 'ServerSimple',
+ debug => 0,
+ );
+ $app;
+}
+
+sub setup_context {
+ my ($self, $app_class) = @_;
+ my $app = $self->_create_app($app_class);
+ local *Angelos::Registrar::context = sub {$app};
+}
+
1;
View
25 angelos-core/lib/Angelos/Script/Command/Generate/Flavor/App.pm
@@ -305,31 +305,8 @@ template: |
file: lib/____var-module_path-var____/Schema.pm
template: |
package [% module %]::Schema;
- use Mouse;
- use [% module %]::Config;
- extends qw(DBIx::Class::Schema);
-
- sub master {
- my $class = shift;
- my $connect_info = $class->config->{'Model::DBIC'}{'connect_info'};
- my $schema = $class->connect( @{$connect_info} );
- return $schema;
- }
-
- sub slave {
- my $class = shift;
- return unless $class->config->{'Model::DBIC::Slave'};
- my $connect_info = $class->config->{'Model::DBIC::Slave'}{'connect_info'};
- my $schema = $class->connect( @{$connect_info} );
- return $schema;
- }
-
- sub config {
- [% module %]::Config->instance;
- }
+ use base qw(Angelos::ORM::DBIC::Schema);
- no Mouse;
- __PACKAGE__->meta->make_immutable;
1;
---
file: lib/____var-module_path-var____/Cache.pm
Please sign in to comment.
Something went wrong with that request. Please try again.