[gimp-perl] Implement, test, doc full(er) tied %Gimp::Data.
- From: Ed J <edj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-perl] Implement, test, doc full(er) tied %Gimp::Data.
- Date: Mon, 26 May 2014 06:10:37 +0000 (UTC)
commit 7e09a0bf0edfe09988c8f09eda685a1e21250fa6
Author: Ed J <edj src gnome org>
Date: Mon May 26 07:10:22 2014 +0100
Implement, test, doc full(er) tied %Gimp::Data.
Gimp/Data.pm | 48 ++++++++++++++++++++++--------------------------
t/data.t | 10 ++++++++++
2 files changed, 32 insertions(+), 26 deletions(-)
---
diff --git a/Gimp/Data.pm b/Gimp/Data.pm
index 05d4b58..5f22771 100644
--- a/Gimp/Data.pm
+++ b/Gimp/Data.pm
@@ -42,10 +42,30 @@ sub STORE {
}
sub EXISTS {
- $_[0]->FETCH ? 1 : ();
+ FETCH(@_) ? 1 : ();
}
-tie (%Gimp::Data, 'Gimp::Data');
+my @allkeys;
+my $key_index;
+sub FIRSTKEY {
+ @allkeys = Gimp->get_parasite_list;
+ $key_index = 0;
+ $allkeys[$key_index];
+}
+
+sub NEXTKEY {
+ die "NEXTKEY: expected last key $allkeys[$key_index] but got $_[1]\n"
+ unless $allkeys[$key_index] eq $_[1];
+ $allkeys[++$key_index];
+}
+
+sub DELETE {
+ my $value = FETCH(@_);
+ Gimp->detach_parasite($_[1]);
+ $value;
+}
+
+tie %Gimp::Data, __PACKAGE__;
1;
__END__
@@ -86,28 +106,6 @@ restart of the Gimp application.
C<Gimp::Data> will freeze your data when you pass in a reference. On
retrieval, the data is thawed again. See L<Data::Dumper> for more info.
-=head1 PERSISTENCE
-
-C<Gimp::Data> contains the following functions to ease applications where
-persistence for perl data structures is required:
-
-=over 4
-
-=item Gimp::Data::freeze(reference)
-
-Freeze (serialize) the reference.
-
-=item Gimp::Data::thaw(data)
-
-Thaw (unserialize) the dsata and return the original reference.
-
-=back
-
-=head1 LIMITATIONS
-
-You cannot (yet) iterate through the keys (with C<keys>, C<values>
-or C<each>).
-
=head1 AUTHOR
Marc Lehmann <pcg goof com>
@@ -115,5 +113,3 @@ Marc Lehmann <pcg goof com>
=head1 SEE ALSO
perl(1), L<Gimp>.
-
-=cut
diff --git a/t/data.t b/t/data.t
index bf46d53..293ea06 100644
--- a/t/data.t
+++ b/t/data.t
@@ -21,6 +21,11 @@ for my $pair (@DATA) {
is_deeply($Gimp::Data{$pair->[0]}, $pair->[1], "stored $pair->[0]");
}
+my @found = grep { $_ eq $DATA[0]->[0] } keys %Gimp::Data;
+is(scalar(@found), 1, 'keys %Gimp::Data');
+ found = grep { $_ eq $DATA[0]->[1] } values %Gimp::Data;
+is(scalar(@found), 1, 'values %Gimp::Data');
+
Gimp::Net::gimp_end;
Gimp->import(qw(net_init=spawn/));
@@ -28,6 +33,11 @@ for my $pair (@DATA) {
is_deeply([ $Gimp::Data{$pair->[0]} ], [ $pair->[1] ], "still $pair->[0]");
}
+my $pair = $DATA[0];
+is_deeply(delete $Gimp::Data{$pair->[0]}, $pair->[1], "delete $pair->[0]");
+ok(!exists $Gimp::Data{$pair->[0]}, "exists $pair->[0]");
+
+
Gimp::Net::gimp_end;
done_testing;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]