[Catalyst-commits] r12159 - in
trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog: . Form
Schema/Result
alexn_org at dev.catalyst.perl.org
alexn_org at dev.catalyst.perl.org
Thu Dec 3 12:07:22 GMT 2009
Author: alexn_org
Date: 2009-12-03 12:07:20 +0000 (Thu, 03 Dec 2009)
New Revision: 12159
Modified:
trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Form/Article.pm
trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema.pm
trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema/Result/Article.pm
trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema/Result/ArticleTag.pm
Log:
fixes
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Form/Article.pm
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Form/Article.pm 2009-12-03 10:21:16 UTC (rev 12158)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Form/Article.pm 2009-12-03 12:07:20 UTC (rev 12159)
@@ -24,28 +24,28 @@
$self->field('tags_str')->value($value);
};
-before 'update_model' => sub {
+around 'update_model' => sub {
+ my $orig = shift;
my $self = shift;
my $item = $self->item;
-
- my @tags = split /\s*,\s*/, $self->field('tags_str')->value;
- $item->article_tags->delete if $item->article_id;
- my $tags_rs = $item->result_source->schema->resultset('Tag');
- foreach my $tag (@tags) {
- my $tag_obj = $tags_rs->search({ name => $tag })->first
- || $tags_rs->create({ name => $tag });
- $item->article_tags->create({ tag => $tag_obj });
- }
-};
+ my $schema = $item->result_source->schema;
-after 'update_model' => sub {
- my $self = shift;
- my $item = $self->item;
+ my $changes = sub {
+ $orig->($self, @_);
- my $summary = generate_symmary($item->content);
- $item->update({ summary => $summary })
- if $summary;
+ my @tags = split /\s*,\s*/, $self->field('tags_str')->value;
+ my $tags_rs = $schema->resultset('Tag');
+
+ $item->article_tags->delete;
+ $item->article_tags->create({ tag => { name => $_ } })
+ foreach (@tags);
+
+ my $summary = generate_symmary($item->content);
+ $item->update({ summary => $summary }) if $summary;
+ };
+
+ $schema->txn_do($changes);
};
sub generate_symmary {
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema/Result/Article.pm
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema/Result/Article.pm 2009-12-03 10:21:16 UTC (rev 12158)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema/Result/Article.pm 2009-12-03 12:07:20 UTC (rev 12159)
@@ -18,6 +18,7 @@
data_type => 'datetime' ,
is_nullable => 1,
set_on_create => 1,
+ set_on_update => 1,
},
title => {
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema/Result/ArticleTag.pm
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema/Result/ArticleTag.pm 2009-12-03 10:21:16 UTC (rev 12158)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema/Result/ArticleTag.pm 2009-12-03 12:07:20 UTC (rev 12159)
@@ -18,7 +18,7 @@
},
);
-__PACKAGE__->add_unique_constraint([ qw/article_fk tag_fk/ ]);
+__PACKAGE__->set_primary_key(qw/article_fk tag_fk/);
__PACKAGE__->belongs_to(tag => 'Blog::Schema::Result::Tag', 'tag_fk');
__PACKAGE__->belongs_to(article => 'Blog::Schema::Result::Article', 'article_fk');
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema.pm
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema.pm 2009-12-03 10:21:16 UTC (rev 12158)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Schema.pm 2009-12-03 12:07:20 UTC (rev 12159)
@@ -4,19 +4,8 @@
use warnings;
use Config::Any;
-use File::Spec qw/abs2rel/;
-use File::Basename qw/dirname basename/;
+use base qw(DBIx::Class::Schema);
-use base qw(DBIx::Class::Schema Exporter);
-our @EXPORT_OK = qw(load_schema);
-
__PACKAGE__->load_namespaces;
-sub load_schema {
- # loads catalyst's config
-
- use Blog::Model::DB;
- return Blog::Model::DB->new->schema;
-}
-
1;
More information about the Catalyst-commits
mailing list