</div>
<div class="slide">
-<pre>package MyApp::Schema::Result::Author;
+<pre>package Foo::Schema::Result::Author;
use strict; use warnings;
__PACKAGE__->table('authors');
__PACKAGE__->add_columns(
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many( books =>
- 'MyApp::Schema::Result::Book', 'author_id'
+ 'Foo::Schema::Result::Book', 'author_id'
);
1;
</pre>
</div>
<div class="slide">
-<pre>package MyApp::Schema::Result::Book;
+<pre>package Foo::Schema::Result::Book;
use strict; use warnings;
__PACKAGE__->table('books');
__PACKAGE__->add_columns(
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->belongs_to( author =>
- 'MyApp::Schema::Result::Author', 'author_id'
+ 'Foo::Schema::Result::Author', 'author_id'
);
1;
</pre>
<div class="slide">
<h1>Schema::Loader</h1>
<p>DB -> Perl vs Perl -> DB</p>
-<pre>package MyApp::Schema;
+<pre>package Foo::Schema;
use strict; use warnings;
use base 'DBIx::Class::Schema::Loader';
__PACKAGE__->loader_options({
# elsewhere...
-my $schema = MyApp::Schema->connect($dsn, $user, $pass);
+my $schema = Foo::Schema->connect($dsn, $user, $pass);
</pre>
</div>
<div class="slide">
<h1>Splitting Logic Cleanly</h1>
- <p>MyApp::Schema::Result::Foo = individual row</p>
- <p>MyApp::Schema::ResultSet::Foo = searches / table </p>
+ <p>Foo::Schema::Result::Bar = individual row</p>
+ <p>Foo::Schema::ResultSet::Bar = searches / table </p>
</div>
<div class="slide">
<pre>#!perl
use strict; use warnings;
use lib 'lib';
-use MyApp::Schema;
-my $schema = MyApp::Schema->connect($dns, $user, $pass);
+use Foo::Schema;
+my $schema = Foo::Schema->connect($dns, $user, $pass);
my $author_rs = $schema->resultset('Author');
my $author = $author_rs->create({
name => 'Douglas Adams',
<div class="slide">
<h1>overloading</h1>
-<pre>MyApp::Schema::Result::Book
-MyApp::Schema::ResultSet::Book
-MyApp::Schema::Result::Author
-MyApp::Schema::ResultSet::Book</pre>
+<pre>Foo::Schema::Result::Book
+Foo::Schema::ResultSet::Book
+Foo::Schema::Result::Author
+Foo::Schema::ResultSet::Book</pre>
</div>
<div class="slide">
use strict;
use warnings;
+# Result code here
+
+__PACKAGE__->load_components('InflateColumn');
use DateTime::Format::MySQL;
__PACKAGE__-><strong>inflate_column</strong>(
<strong>date_published</strong> => {
inflate => sub { DateTime::Format::MySQL->parse_date(shift) },
deflate => sub { shift->ymd},
- }
-);
-# Automatic see: DBIx::Class::InflateColumn::DateTime</pre>
- </div>
-
- <div class="slide">
- <h1>Result:: (inflating)</h1>
-<pre>package Foo::Schema::Result::Books;
-use base 'DBIx::Class';
-use strict;
-use warnings;
-
-use DateTime::Format::MySQL;
-
-__PACKAGE__->inflate_column(
- date_published => {
- <strong>inflate => sub { DateTime::Format::MySQL->parse_date(shift) },
- deflate => sub { shift->ymd},</strong>
- }
+ },
);
-# Automatic see: DBIx::Class::InflateColumn::DateTime
-# Automatic see: DBIx::Class::InflateColumn::DateTime
# Automatic see: DBIx::Class::InflateColumn::DateTime</pre>
</div>
<div class="slide">
<h1>ResultSets::</h1>
-<pre>package Foo::Schema::<strong>ResultSet::Books</strong>;
-use base '<strong>DBIx::Class::ResultSet</strong>';
-sub the_ultimate_books {
- my $self = shift;
- <strong>return $self->search({ title => { -like => '%42%' } })</strong>
-}
-sub by_author {
- my ( $self, $author ) = @_;
- return $self->search({ author => $author->id })
-}
-
-1;</pre>
- </div>
-
- <div class="slide">
- <h1>ResultSets::</h1>
-<pre>package Foo::Schema::ResultSet::Books;
-use base 'DBIx::Class::ResultSet';
-sub the_ultimate_books {
- my $self = shift;
- return $self->search({ title => { -like => '%42%' } });
-}
-sub by_author {
- my ( $self, $author ) = @_;
- <strong>return $self->search({ author => $author->id })</strong>
-}
-
-1;</pre>
- </div>
-
- <div class="slide">
- <h1>ResultSets::</h1>
<pre>use Foo::Schema;
-my $book_model = Foo::Schema->resultset('Books');
-my $book_rs = $book_model->the_ultimate_books;
-my @books = $book_rs->all;</pre>
+my $schema = Foo::Schema->connect(...);
+my $book_rs = Foo::Schema->resultset('Book');
+my $book_search = $book_rs->the_ultimate_books;
+my @books = $book_search->all;</pre>
</div>
<div class="slide">
- <h1>ResultSets::chaining</h1>
-<pre>use Foo::Schema;
-my $book_model = Foo::Schema->resultset('Books');
-my $author_model = Foo::Schema->resultset('Authors');
+ <h1>ResultSets: Chaining</h1>
+<pre>
+my $book_rs = $schema->resultset('Book');
+my $author_rs = $schema->resultset('Author');
my $author = $author_model->search({ name => 'Douglas Adams' })->single;
my $book_rs = $book_model->the_ultimate_books->by_author($author);
my @books = $book_rs->all;</pre>
</div>
<div class="slide">
- <h1>ResultSets::chaining</h1>
-<pre>my $book_rs = $book_model
+ <h1>ResultSets: Chaining</h1>
+<pre>$book_rs = $schema->resultset('Book')
->the_ultimate_books
->by_author($author);</pre>
or
-<pre>my $book_rs = $book_model
+<pre>my $book_rs = $schema->resultset('Book')
->the_ultimate_books();
$book_rs = $book_rs->by_author($author);</pre>
<pre># Debug (SQL):