Catalyst-Model-DBIC-Schema

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

          a DSN (dandv, RT #47101)

0.24  Tue Jun 16 06:18:58 PDT 2009
        - Add tests for issues with Class::C3 which are caused to
          applications which use new Catalyst but old DBIC, and have
          use Class::C3 in the MyApp class (t0m)
        - die on empty schema
        - create=dynamic deprecation warning
        - helper passes loader opts to dynamic schemas
        - conversion to Moose
        - cursor caching support (via
          Catalyst::TraitFor::Model::DBIC::Schema::Caching)
        - ::Storage::Replicated support (via ::Replicated trait)
        - switch to hashref connect_info for DBIC 8100
        - better helper option parsing, with support for more options
        - more tests

0.23  Sun Mar  8 20:30:02 GMT 2009
        - Kill a couple of warnings (one due to MRO::Compat)

0.22  Tue Mar  3 15:54:19 UTC 2009

README  view on Meta::CPAN

  connect_info
    Your connect_info args normalized to hashref form (with
    dsn/user/password.) See "connect_info" in DBIx::Class::Storage::DBI for
    more info on the hashref form of "connect_info".

  model_name
    The model name Catalyst uses to resolve this model, the part after
    "::Model::" or "::M::" in your class name. E.g. if your class name is
    "MyApp::Model::DB" the "model_name" will be "DB".

  _default_cursor_class
    What to reset your "cursor_class" in DBIx::Class::Storage::DBI to if a
    custom one doesn't work out. Defaults to
    DBIx::Class::Storage::DBI::Cursor.

ATTRIBUTES FROM MooseX::Traits::Pluggable
  _original_class_name
    The class name of your model before any "traits" are applied. E.g.
    "MyApp::Model::DB".

  _traits
    Unresolved arrayref of traits passed in the config.

lib/Catalyst/Helper/Model/DBIC/Schema.pm  view on Meta::CPAN

and a Model which references it:

  script/myapp_create.pl model CatalystModelName DBIC::Schema \
    MyApp::SchemaClass create=static dbi:mysql:foodb myuname mypass

Same, with extra connect_info args
user and pass can be omitted for sqlite, since they are always empty

  script/myapp_create.pl model CatalystModelName DBIC::Schema \
    MyApp::SchemaClass create=static dbi:SQLite:foo.db \
    AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \
    on_connect_do='["select 1", "select 2"]' quote_names=1

B<ON WINDOWS COMMAND LINES QUOTING RULES ARE DIFFERENT>

In C<cmd.exe> the above example would be:

  script/myapp_create.pl model CatalystModelName DBIC::Schema \
    MyApp::SchemaClass create=static dbi:SQLite:foo.db \
    AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \
    on_connect_do="[\"select 1\", \"select 2\"]" quote_names=1

Same, but with extra Schema::Loader args (separate multiple values by commas):

  script/myapp_create.pl model CatalystModelName DBIC::Schema \
    MyApp::SchemaClass create=static db_schema=foodb components=Foo,Bar \
    exclude='^(wibble|wobble)$' moniker_map='{ foo => "FOO" }' \
    dbi:Pg:dbname=foodb myuname mypass

Coderefs are also supported:

lib/Catalyst/Model/DBIC/Schema.pm  view on Meta::CPAN

Your connect_info args normalized to hashref form (with dsn/user/password.) See
L<DBIx::Class::Storage::DBI/connect_info> for more info on the hashref form of
L</connect_info>.

=head2 model_name

The model name L<Catalyst> uses to resolve this model, the part after
C<::Model::> or C<::M::> in your class name. E.g. if your class name is
C<MyApp::Model::DB> the L</model_name> will be C<DB>.

=head2 _default_cursor_class

What to reset your L<DBIx::Class::Storage::DBI/cursor_class> to if a custom one
doesn't work out. Defaults to L<DBIx::Class::Storage::DBI::Cursor>.

=head1 ATTRIBUTES FROM L<MooseX::Traits::Pluggable>

=head2 _original_class_name

The class name of your model before any L</traits> are applied. E.g.
C<MyApp::Model::DB>.

=head2 _traits

lib/Catalyst/Model/DBIC/Schema.pm  view on Meta::CPAN


has connect_info => (is => 'rw', isa => ConnectInfo, coerce => 1);

has model_name => (
    is => 'ro',
    isa => Str,
    required => 1,
    lazy_build => 1,
);

has _default_cursor_class => (
    is => 'ro',
    isa => LoadableClass,
    default => 'DBIx::Class::Storage::DBI::Cursor',
);

has schema => (is => 'rw', isa => Schema);

my $app_class;

before COMPONENT => sub {

lib/Catalyst/Model/DBIC/Schema.pm  view on Meta::CPAN

            $self->connect_info($schema_class->storage->connect_info);
        }
        else {
            die "Either ->config->{connect_info} must be defined for $class"
                  . " or $schema_class must have connect info defined on it."
		  . " Here's what we got:\n"
		  . Dumper($args);
        }
    }

    if (exists $self->connect_info->{cursor_class}) {
        eval { use_module($self->connect_info->{cursor_class}) }
            or croak "invalid connect_info: Cannot load your cursor_class"
        . " ".$self->connect_info->{cursor_class}.": $@";
    }

    $self->setup($args);

    my $is_installed = defined $self->composed_schema;

    if (not $is_installed) {
        $self->composed_schema($self->compose_namespaces ?
            $schema_class->compose_namespace($class)
            :

lib/Catalyst/Model/DBIC/Schema.pm  view on Meta::CPAN


    foreach my $moniker (@sources) {
        my $classname = "${class}::$moniker";
        *{"${classname}::ACCEPT_CONTEXT"} = sub {
            shift;
            shift->model($self->model_name)->resultset($moniker);
        }
    }
}

sub _reset_cursor_class {
    my $self = shift;

    if ($self->storage->can('cursor_class')) {
	$self->storage->cursor_class($self->_default_cursor_class)
	    if $self->storage->cursor_class ne $self->_default_cursor_class;
    }
}

{
    my %COMPOSED_CACHE;

    sub composed_schema {
	my $self = shift;
	my $class = $self->_original_class_name;
	my $store = \$COMPOSED_CACHE{$class}{$self->schema_class};

lib/Catalyst/TraitFor/Model/DBIC/Schema/Caching.pm  view on Meta::CPAN


has caching => (is => 'rw', isa => Int, default => 1);

after setup => sub {
    my $self = shift;

    return if !$self->caching;

    $self->caching(0);

    my $cursor_class = $self->connect_info->{cursor_class}
        || 'DBIx::Class::Cursor::Cached';

    unless (eval { use_module($cursor_class) }) {
        carp "Caching disabled, cannot load cursor class"
            . " $cursor_class: $@";
        return;
    }

    unless ($cursor_class->can('clear_cache')) {
        carp "Caching disabled, cursor_class $cursor_class does not"
             . " support it.";
        return;
    }

    $self->connect_info->{cursor_class} = $cursor_class;
    $self->caching(1);
};

before ACCEPT_CONTEXT => sub {
    my ($self, $c) = @_;

    return $self unless 
        $self->caching;

    unless ($c->can('cache') && ref $c->cache) {
        $c->log->warn("DBIx::Class cursor caching disabled, you don't seem to"
            . " have a working Cache plugin.");
        $self->caching(0);
        $self->_reset_cursor_class;
        return $self;
    }

    if (ref $self->schema->default_resultset_attributes) {
        $self->schema->default_resultset_attributes->{cache_object} =
            $c->cache;
    } else {
        $self->schema->default_resultset_attributes({
            cache_object => $c->cache
        });



( run in 0.264 second using v1.01-cache-2.11-cpan-4d50c553e7e )