On Sep 27, 2007, at 5:00 PM, Sergei Steshenko wrote:

> --- Torsten Schoenfeld <[EMAIL PROTECTED]> wrote:
>
>> On Thu, 2007-09-20 at 09:45 -0700, MICHAEL MCGINN wrote:

>>> Scalar found where operator expected at blib/lib/Gtk2.pm line 139,
>>> near "$connect_object ? $connect_object"
>>>         (Missing operator before  $connect_object?)
>>> syntax error at blib/lib/Gtk2.pm line 139, near "$connect_object ?"
>>>   (Might be a runaway multi-line ?? string starting on line 131)
>>> Global symbol "$func" requires explicit package name at
>>> blib/lib/Gtk2.pm line 131.
>>> BEGIN not safe after errors--compilation aborted at blib/lib/ 
>>> Gtk2.pm line 160.
>>> Compilation failed in require.
>>> BEGIN failed--compilation aborted.
>>
>> Does anyone know what's up with that?  I can't see the error.   
>> Relevant lines:
>>
>> 123  sub _do_connect {
>>        my ($object,
>>            $signal_name,
>>            $user_data,
>>            $connect_object,
>>            $flags,
>>            $handler) = @_;
>>
>> 131    my $func = $flags & qw/after/ ? 'signal_connect_after' :  
>> 'signal_connect';
>>
>>        # we get connect_object when we're supposed to call
>>        # signal_connect_object, which ensures that the data (an object)
>>        # lives as long as the signal is connected.  the bindings take
>>        # care of that for us in all cases, so we only have  
>> signal_connect.
>>        # if we get a connect_object, just use that instead of user_data.
>>        $object->$func($signal_name => $handler,
>> 139                   $connect_object ? $connect_object : $user_data);
>>      }


> And what does exactly
>
> 131     my $func = $flags & qw/after/ ? 'signal_connect_after' :  
> 'signal_connect';
>
> line mean ?


'Set the variable $func to the string "signal_connect_after" if the  
Glib::Flags array referred to by $flags contains "after", else set it  
to "signal_connect".'

That is, this line tries to determine whether we're supposed to call  
Glib::Object::signal_connect() or Glib::Object::signal_connect_after().


This code is, in fact, adapted from Gtk2::GladeXML.pm:

http://gtk2-perl.cvs.sourceforge.net/gtk2-perl/gtk2-perl-xs/Glade/ 
GladeXML.pm?revision=1.31&view=markup

With a change to account for the fact that _do_connect() gets a  
GConnectFlags argument instead of a boolean.

http://library.gnome.org/devel/gobject/stable/gobject- 
Signals.html#GConnectFlags


> Specifically, the '$flags & qw/after/' part ?
>
> What is the meaning of '&' ?

$flags is supposed to be a Glib::Flags variable, so '&' means  
"intersection of two bitsets", just as it does in C.  This is because  
Glib::Flags overloads several operators to allow you to do bitset  
operations without resorting to C-ish bit math.

http://gtk2-perl.sourceforge.net/doc/pod/Glib.html#This_Is_Now_That

    Flags have some additional magic abilities in the form of  
overloaded operators:
    ...
      * or &   intersection of two bitsets ("and")



> Does 'qw' accept '/' as delimiter ?

Yes.  http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators

$ perl -e 'printf "-%s-\n", qw/ hello /'
-hello-



> Again, on '$flags & qw/after/' - '$flags' is scalar and 'qw/after/'  
> is list,
> so what was the intended operation ?

The overloaded & operator will try to convert the second scalar to a  
Glib::Flags by calling gperl_convert_flags().  This will handle three  
cases: a reference to a blessed Glib::Flags reference, a reference to  
an array of strings, and a plain string.  Thus, you can do all three of

     $flags & $other_flags
     $flags & [qw/value value/]
     $flags & 'value'

And qw/oneword/ is just another way to write 'oneword'.



... SO ...  that code *should* be fine.  Some parens wouldn't hurt   
(e.g.,  my $func = ($flags & 'value') ? 'signal_connect_after' :  
'signal_connect';) but should not be necessary...  unless the  
particular version of the perl interpreter used by the original  
poster is somehow misparsing the line.

So, Michael, what version of perl are you using?




--
I hate to break it to you, but magic data pixies don't exist.
   -- Simon Cozens


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to