It'd be good if Glib::Flags had overloaded += as well as + so you could
go

        $f += 'val';

I think the basic overload can be used without too much trouble, the new
object returned being assigned to the destination automatically by
"overload".

I remember a long time ago making mutators which peeked into the target
object and on refcount==1 changed it in-place instead of creating a new
one.  I guess that's possible with Glib::Flags too, though it's small
enough it might not be worth bothering.


--- GType.xs	02 Jun 2008 09:38:05 +1000	1.92
+++ GType.xs	20 Jun 2008 18:10:11 +1000	
@@ -2773,7 +2773,7 @@
         RETVAL
 
 SV *
-union (SV *a, SV *b, int swap)
+union (SV *a, SV *b, SV *swap)
     ALIAS:
         sub = 1
         intersect = 2
@@ -2783,12 +2783,13 @@
 {
 	GType gtype;
 	const char *package;
-        gint a_, b_;
+        gint a_, b_, swap_;
 
 	package = sv_reftype (SvRV (a), TRUE);
 	gtype = gperl_fundamental_type_from_package (package);
-        a_ = gperl_convert_flags (gtype, swap ? b : a);
-        b_ = gperl_convert_flags (gtype, swap ? a : b);
+        swap_ = SvTRUE (swap);
+        a_ = gperl_convert_flags (gtype, swap_ ? b : a);
+        b_ = gperl_convert_flags (gtype, swap_ ? a : b);
 
         switch (ix) {
           case 0: a_ |= b_; break;
--- Glib.pm	23 May 2008 09:49:02 +1000	1.121
+++ Glib.pm	20 Jun 2008 17:54:15 +1000	
@@ -73,13 +73,16 @@
 
 use overload
    'bool' => \&bool,
-   '+'    => \&union,     '|'    => \&union,
-   '-'    => \&sub,
+   '+'    => \&union,     '+='   => \&union,
+   '|'    => \&union,     '|='   => \&union,
+   '-'    => \&sub,       '-='   => \&sub,
+   '*'    => \&intersect, '*='   => \&intersect,
+   '&'    => \&intersect, '&='   => \&intersect,
+   '/'    => \&xor,       '/='   => \&xor,
+   '^'    => \&xor,       '^='   => \&xor,
    '>='   => \&ge,
    '=='   => \&eq,        'eq'   => \&eq,
    '!='   => \&ne,        'ne'   => \&ne,
-   '*'    => \&intersect, '&'    => \&intersect,
-   '/'    => \&xor,       '^'    => \&xor,
    '@{}'  => \&as_arrayref,
    '""'   => sub { "[ @{$_[0]} ]" },
    fallback => 1;
--- c.t	23 May 2008 09:49:02 +1000	1.12
+++ c.t	20 Jun 2008 18:12:47 +1000	
@@ -13,7 +13,7 @@
 
 #########################
 
-use Test::More tests => 32;
+use Test::More tests => 34;
 BEGIN { use_ok('Glib') };
 
 #########################
@@ -40,6 +40,16 @@
 eval { my $h = Glib::Flags->new (['readable']); };
 ok ($@, "Will croak on trying to create plain old Glib::Flags");
 
+{ $f = Glib::ParamFlags->new (['readable']); # with array
+  my $g = $f;
+  $g += 'writable';
+  ok ($g == ['readable', 'writable'],
+      "overloaded +=");
+  ok ($f == ['readable'],
+      "overloaded += leaves original unchanged");
+}
+
+
 #########################
 
 $@ = undef;
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to