Re: Glib::Flags overload !=



Kevin Ryde wrote:

I saw in the Glib pod that "==" is overloaded, which made me try to use
"!=" too :-).  I wonder if that could be offered fairly easily.

I think the attached patch should do.

-- 
Bye,
-Torsten
Index: GType.xs
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/GType.xs,v
retrieving revision 1.88
diff -u -d -p -r1.88 GType.xs
--- GType.xs    4 May 2008 12:49:53 -0000       1.88
+++ GType.xs    4 May 2008 12:57:54 -0000
@@ -2719,7 +2719,8 @@ as_arrayref (SV *a, b, swap)
 int
 eq (SV *a, SV *b, int swap)
     ALIAS:
-       ge = 1
+       ne = 1
+       ge = 2
 
     CODE:
 {
@@ -2735,7 +2736,8 @@ eq (SV *a, SV *b, int swap)
        RETVAL = FALSE;
         switch (ix) {
           case 0: RETVAL = a_ == b_; break;
-          case 1: RETVAL = (a_ & b_) == b_; break;
+          case 1: RETVAL = a_ != b_; break;
+          case 2: RETVAL = (a_ & b_) == b_; break;
         }
 }
     OUTPUT:
Index: Glib.pm
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/Glib.pm,v
retrieving revision 1.120
diff -u -d -p -r1.120 Glib.pm
--- Glib.pm     30 Mar 2008 17:26:01 -0000      1.120
+++ Glib.pm     4 May 2008 12:57:54 -0000
@@ -77,6 +77,7 @@ use overload
    '-'    => \&sub,
    '>='   => \&ge,
    '=='   => \&eq,        'eq'   => \&eq, # eq for is_deeply in Test::More
+   '!='   => \&ne,
    '*'    => \&intersect, '&'    => \&intersect,
    '/'    => \&xor,       '^'    => \&xor,
    '@{}'  => \&as_arrayref,
Index: t/c.t
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/t/c.t,v
retrieving revision 1.9
diff -u -d -p -r1.9 c.t
--- t/c.t       4 May 2008 12:38:55 -0000       1.9
+++ t/c.t       4 May 2008 12:57:54 -0000
@@ -12,7 +12,7 @@ use warnings;
 
 #########################
 
-use Test::More tests => 17;
+use Test::More tests => 19;
 BEGIN { use_ok('Glib') };
 
 #########################
@@ -184,6 +184,9 @@ is_deeply (\ { $obj->get ('some_flags') 
 ok ($obj->get ('some_flags') & $obj->get ('some_flags'),
     '& is overloaded');
 
+ok (! $obj->get ('some_flags') != [qw/value-one value-two/], '!= is overloaded');
+ok ($obj->get ('some_flags') != [qw/value-one/], '!= is overloaded');
+
 __END__
 
 Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for the


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]