[Kde-bindings] PerlQt constructor syntax

Dominique Dumont domi.dumont at free.fr
Thu Jun 4 17:24:08 UTC 2009


Le Wednesday 27 May 2009 10:44:23 Ashley Winters, vous avez écrit :
> Both versions work in PerlQt 3. In fact, the code involved is literally:
>
>     # for my $class ("Qt::PushButton") ...
>     *{ $class } = sub {
>         $class->new(@_);
>     } unless defined &{ $class };
>
> The shortened form was encouraged to ease the conversion from C++.

You mean that some Qt application were converted from C++ to Perl ?

> It was an arbitrary decision. I liked the possibility of writing programs
> which looked like
> http://perlqt.sourceforge.net/index.php?page=viewcode&file=examples/drawlin
>es/drawlines.pl

The risk is that some Perl programmer will be puzzled and may be driven away.  

> > Is there another reason why the this() value is necessary?
>
> It exists primarily to support unqualified object attributes. There are
> many classes to do such things today, although now I would turn to Moose.
> The 'this' hack existed because C<has foo => (is => ro)> wasn't an option
> back then. If MooseX::Declare was more mature, it would be the perfect
> platform for Qt the way I always wanted it.

I understand what you mean, OO programming with Perl5 is not always fun. I 
hope this will get better with Perl6.

In the meantime, we are stuck with the decision made for Perl5 OO paradigm. I 
understand why you added some trickery to make PerlQt programming closer to 
the experience you has with C++. But this has the drawback of introducing a 
style which is not easy for "regular" Perl programmers to grasp. These 
programmers may choose to use other toolkits instead of Qt.

Another risk is portability across Perl versions. Did you have trouble to port 
Qt binding from old Perl (was it 5.003?) to Perl 5.10?

> AUTOLOAD was always tricky. There are hacks upon hacks required to get it
> to work to any reliable degree across perl versions, and then more hacks on
> top to make it perform at any respectable speed. It all depends on what
> versions of perl you want to support.

Agreed. Autoloading is often too tricky.

All the best





More information about the Kde-bindings mailing list