[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
$flags->as_arrayref directly
- From: Kevin Ryde <user42 zip com au>
- To: gtk-perl-list gnome org
- Subject: $flags->as_arrayref directly
- Date: Thu, 27 Nov 2008 07:41:36 +1100
I thought to call a Glib::Flags as_arrayref directly like
myexpression()->as_arrayref
inspired by other as_arrayref funcs, and because it seemed a little
cleaner than lots of brackets
[ {myexpression()}]
Alas as_arrayref requires the "overload" three args. I wonder if that
could be relaxed per below. The test case is actually a good example of
the method looking cleaner than the overload, though no doubt it's a
matter of personal preference.
I wondered if the "PROTOTYPE:" in the xs was meant to allow this
already, except it doesn't. :-) That's something else is it?
Index: GType.xs
===================================================================
--- GType.xs (revision 1054)
+++ GType.xs (working copy)
@@ -2780,10 +2780,14 @@
=for arg swap (integer)
=cut
SV *
-as_arrayref (SV *a, b, swap)
+as_arrayref (SV *a, ...)
PROTOTYPE: $;@
CODE:
{
+ /* overload @{} calls here with the usual three args "a,b,swap", but
+ * "b" and "swap" have no meaning. Using "..." to ignore them lets
+ * users call method-style with no args "$f->as_arrayref" too.
+ */
GType gtype;
const char *package;
gint a_;
Index: t/c.t
===================================================================
--- t/c.t (revision 1054)
+++ t/c.t (working copy)
@@ -13,7 +13,7 @@
#########################
-use Test::More tests => 34;
+use Test::More tests => 35;
BEGIN { use_ok('Glib') };
#########################
@@ -216,6 +216,7 @@
is ($obj->get ('some_enum'), 'value-two', 'enum property, after set');
is_deeply (\ { $obj->get ('some_flags') }, ['value-one'], 'flags property');
+is_deeply ($obj->get('some_flags')->as_arrayref, ['value-one'], 'flags property');
$obj->set (some_flags => ['value-one', 'value-two']);
is_deeply (\ { $obj->get ('some_flags') }, ['value-one', 'value-two'],
'flags property, after set');
--
"Never bolt your door with a boiled carrot."
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]