Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First release

  • Loading branch information...
commit a1c3b5e249b723321b0b2a1872c28ae2a9e57b7b 1 parent 9b18389
@Getty authored
View
13 dist.ini
@@ -1,7 +1,16 @@
name = DBIx-Class-AlwaysUpdate
-author = Torsten Raudssus <torsten@raudssus.de>
+author = Torsten Raudssus <torsten@raudss.us> L<http://raudss.us/>
license = Perl_5
-copyright_holder = Torsten Raudssus
+copyright_holder = Raudssus Social Software
copyright_year = 2011
[@GETTY]
+
+[Prereqs]
+DBIx::Class = 0.08195
+
+[Prereqs / TestRequires]
+Test::More = 0.90
+Test::DBIC::Schema::Connector = 0
+
+
View
35 lib/DBIx/Class/AlwaysUpdate.pm
@@ -1,5 +1,38 @@
+package DBIx::Class::AlwaysUpdate;
+# ABSTRACT: Always update the result on ->update, independent of changes
use strict;
use warnings;
-package DBIx::Class::AlwaysUpdate;
+use base 'DBIx::Class::Core';
+
+sub is_changed { 1 };
+sub is_column_changed { 1 };
+sub get_dirty_columns { shift->get_columns }
1;
+
+=head1 SYNOPSIS
+
+ package MyApp::Schema::Result::CD;
+
+ __PACKAGE__->load_components( qw( AlwaysUpdate ) );
+
+=head1 DESCRIPTION
+
+This little helper will bring your result to always update all of its row, regardless of the change state or if its dirty or not. Its a very simple hack that overloads all functions which are required to identify if the data has changed. Be aware that this also means that you are unable to detect for yourself, if there was made a change.
+
+=head1 SUPPORT
+
+IRC
+
+ Join #dbix-class on irc.perl.org and ask for Getty.
+
+Repository
+
+ http://github.com/Getty/p5-dbix-class-alwaysupdate
+ Pull request and additional contributors are welcome
+
+Issue Tracker
+
+ http://github.com/Getty/p5-dbix-class-alwaysupdate/issues
+
+=cut
View
7 t/00-load.t
@@ -0,0 +1,7 @@
+use strict;
+use warnings;
+use Test::More;
+
+use_ok('DBIx::Class::AlwaysUpdate');
+
+done_testing;
View
43 t/01-simple.t
@@ -0,0 +1,43 @@
+use strict;
+use warnings;
+use Test::More;
+
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+
+use DBIx::Class::Storage::Statistics;
+use Test::DBIC::Schema::Connector;
+use DCAUTSchema;
+use Data::Dumper;
+
+my $schema = test_dbic_schema_connect('DCAUTSchema');
+
+my @queries;
+
+{
+ package LastQueryMagic;
+ use strict;
+ use base 'DBIx::Class::Storage::Statistics';
+
+ sub query_start {
+ my $self = shift;
+ push @queries, {
+ sql => shift,
+ params => \@_,
+ };
+ }
+}
+
+$schema->storage->debug(1);
+$schema->storage->debugobj(LastQueryMagic->new);
+
+my $insert = $schema->resultset('DCAUT')->create({ id => 5 });
+shift @queries; # ignore this query
+
+$insert->update;
+
+my $query = shift @queries;
+
+is($query->{params}->[0],'\'5\'', "Checking for update try in last params");
+
+done_testing;
View
7 t/lib/DCAUTSchema.pm
@@ -0,0 +1,7 @@
+package DCAUTSchema;
+
+use base qw/DBIx::Class::Schema/;
+
+__PACKAGE__->load_namespaces();
+
+1;
View
10 t/lib/DCAUTSchema/Result/DCAUT.pm
@@ -0,0 +1,10 @@
+package DCAUTSchema::Result::DCAUT;
+
+use base qw/DBIx::Class::Core/;
+
+__PACKAGE__->load_components( qw( AlwaysUpdate ) );
+__PACKAGE__->table('dcaut');
+__PACKAGE__->add_columns(qw/id/);
+__PACKAGE__->set_primary_key('id');
+
+1;
Please sign in to comment.
Something went wrong with that request. Please try again.