summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2006-02-03 04:36:46 +0000
committerJason Woodward2006-02-03 04:36:46 +0000
commitf4d221c64fddd4ae8d855e8cb33d00c7cb62b502 (patch)
tree76d6d1e460a0346be57e5826d380f6d5db150080
parent8eae4e3736e66e94de8ef5e262af15a67233a0b7 (diff)
downloadJaos-DBI-f4d221c64fddd4ae8d855e8cb33d00c7cb62b502.tar.gz
added is_changed method
-rw-r--r--Changes1
-rw-r--r--MANIFEST1
-rw-r--r--lib/Jaos/DBI.pm32
-rw-r--r--t/04full.t5
4 files changed, 28 insertions, 11 deletions
diff --git a/Changes b/Changes
index be7a3b7..af44196 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,7 @@ Revision history for Perl extension Jaos::DBI
- added 04full.t
- updated POD
- added additional search methods
+ - added is_changed
0.2
- initial release
diff --git a/MANIFEST b/MANIFEST
index b3d1532..d0fcff2 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -3,7 +3,6 @@ Changes
lib/Jaos/DBI.pm
Makefile.PL
MANIFEST This list of files
-META.yml
README
t/01use.t
t/02pod.t
diff --git a/lib/Jaos/DBI.pm b/lib/Jaos/DBI.pm
index b38744f..4f6b007 100644
--- a/lib/Jaos/DBI.pm
+++ b/lib/Jaos/DBI.pm
@@ -64,7 +64,8 @@ Jaos::DBI - Jaos DBI object similar to Class::DBI
# modify
$user->email('newaddress@foo.com'); # setting attribute updates the database
$user->delete();
- $user->update() unless $user->manual_update == 1;
+ $user->update() unless $user->manual_update;
+ $user->update() if $user->is_changed;
User->delete(nick => 'zaphod', email => 'newaddress@foo.com');
=head1 DESCRIPTION
@@ -90,6 +91,7 @@ __PACKAGE__->mk_classdata('_db_password');
__PACKAGE__->mk_classdata('_db_options');
__PACKAGE__->mk_classdata('_base_select');
__PACKAGE__->mk_classdata('_manual_update' => 0);
+__PACKAGE__->mk_classdata('_is_changed' => 0);
=head1 METHODS
@@ -296,6 +298,21 @@ sub manual_update
$self->_manual_update();
}
+=head2 is_changed
+
+Returns true if object has been modified.
+
+=cut
+
+sub is_changed
+{
+ my $self = shift;
+ if (@_) {
+ $self->_is_changed(@_);
+ }
+ $self->_is_changed();
+}
+
=head2 sequence
Get or set the tables sequence. This is used to generate unique primary keys.
@@ -381,8 +398,6 @@ sub insert
my $sql = "insert into $table (";
my $seq = undef;
- #$self->begin_work();
-
$seq = $self->sequence_nextval();
if ($seq) {
@@ -404,7 +419,6 @@ sub insert
};
$seq = $self->sequence_currval();
- #$self->commit();
if ($seq) {
return $self->retrieve($seq);
@@ -627,7 +641,6 @@ sub delete
return;
}
- #$self->begin_work();
#print STDERR "delete:$sql [",join(',',@values),"]\n";
eval {
my $stmt = $self->prepare($sql) or die "Failed to prepare [$sql]";
@@ -636,13 +649,11 @@ sub delete
};
if ($@) {
warn $@;
- #$self->rollback();
return;
} else {
if ( ref $self ) {
undef %$self;
}
- #$self->commit();
return 1;
}
@@ -668,7 +679,12 @@ sub set
{
my ($self, $key) = splice(@_, 0, 2);
$self->SUPER::set($key, @_);
- $self->_update($key) unless ($self->manual_update == 1);
+ if ($self->manual_update) {
+ $self->is_changed(1);
+ } else {
+ $self->_update($key)
+ }
+
}
=head2 update
diff --git a/t/04full.t b/t/04full.t
index 8a4343f..1b5c735 100644
--- a/t/04full.t
+++ b/t/04full.t
@@ -13,7 +13,7 @@ BEGIN
or plan skip_all =>
"DBD::CSV is needed for this test";
- plan tests => 23;
+ plan tests => 25;
unlink('foo_table') if ( -e 'foo_table' );
my $dbh = DBI->connect('DBI:CSV:f_dir=./') or die $DBI::errstr;
@@ -32,7 +32,6 @@ my @base_class_methods = qw/
search search_like search_ilike search_or search_or_like search_or_ilike
search_where retrieve_all retrieve
prepare begin_work commit rollback
-
/;
can_ok('Foo',@base_class_methods);
@@ -55,11 +54,13 @@ ok($obj->name eq 'jason','testing generated method');
eval{$obj->begin_work;};
$obj->name('j');
$obj->commit;
+ok($obj->manual_update(1),'setting manual update');
ok($obj->name eq 'j','testing generated method');
ok($obj->password eq 'pass','testing generated method');
ok($obj->email eq 'woodwardj@jaos.org','testing generated method');
$obj->set('email','foo@bar');
ok($obj->get('email') eq 'foo@bar','testing get() method');
+ok($obj->is_changed,'testing is_changed');
ok($obj->update(),'update() method');
ok($obj->delete(),'delete() method');