]> err.no Git - libchamplain/commitdiff
The accessors/modifiers are now done through XS.
authorEmmanuel Rodriguez <emmanuel.rodriguez@gmail.com>
Sun, 14 Jun 2009 10:58:04 +0000 (12:58 +0200)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 14 Jun 2009 15:11:17 +0000 (11:11 -0400)
Before the object wasn't registered as a GType and all marshalling had to be
done by hand. Furthermore the C structure was transformed into a Per hash
making the hash fields out of sync with the C structure. Now that the object is
a GType (GBoxed) everything is more natural.

bindings/perl/Champlain/lib/Champlain.pm
bindings/perl/Champlain/t/ChamplainMapSourceDesc.t
bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs

index 38164f21c9899bec2250b8485fef0ac21cb760dc..eb082366e023edcae555a790db1b51021bb75474 100644 (file)
@@ -149,20 +149,4 @@ __PACKAGE__->bootstrap($VERSION);
 
 package Champlain::MapSourceDesc;
 
-BEGIN {
-       # Create getters and setters for the properties
-       my @properties = qw(
-               id name license license_uri min_zoom_level max_zoom_level projection
-       );
-       foreach my $property (@properties) {
-               my $get_name = join '::', __PACKAGE__, "get_$property";
-               my $set_same = join '::', __PACKAGE__, "set_$property";
-               my $getter = sub {return $_[0]->{$property};};
-               my $setter = sub {return $_[0]->{$property} = $_[1];};
-               no strict;
-               *{$get_name} = $getter;
-               *{$set_same} = $setter;
-       }
-}
-
 1;
index c4e2ad3f89b7532341c2b467fb4684b7e144b1bc..5b88650e94ac5c2362d3010e29a339e1ec3ba9a2 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Clutter::TestHelper tests => 25;
+use Clutter::TestHelper tests => 18;
 
 use Champlain ':maps';
 
@@ -24,31 +24,23 @@ sub test_get_set {
        ok(@maps >= 5, "Maps factory has the default maps");
        
        # Find the OAM map and check that the it's properly described
-       my @found = grep { $_->{id} eq Champlain::MapSourceFactory->OAM } @maps;
-       is(scalar(@found), 1);
+       my @found = grep { $_->get_id eq Champlain::MapSourceFactory->OAM } @maps;
+       is(scalar(@found), 1, "Found a single map matching OAM");
        if (! @found) {
                fail("Can't test a Champlain::MapSourceDesc without a map description") for 1 .. 22;
                return;
        }
 
+       # Getters
        my ($oam) = @found;
        isa_ok($oam, 'Champlain::MapSourceDesc');
-       is($oam->id, Champlain::MapSourceFactory->OAM);
-       is($oam->name, 'OpenAerialMap');
-       is($oam->license, "(CC) BY 3.0 OpenAerialMap contributors");
-       is($oam->license_uri, 'http://creativecommons.org/licenses/by/3.0/');
-       is($oam->min_zoom_level, 0);
-       is($oam->max_zoom_level, 17);
-       is($oam->projection, 'mercator');
-
-       # Getters
-       is($oam->get_id, $oam->{id}, "get_id()");
-       is($oam->get_name, $oam->{name}, "get_name()");
-       is($oam->get_license, $oam->{license}, "get_license()");
-       is($oam->get_license_uri, $oam->{license_uri}, "get_license_uri()");
-       is($oam->get_min_zoom_level, $oam->{min_zoom_level}, "get_min_zoom_level()");
-       is($oam->get_max_zoom_level, $oam->{max_zoom_level}, "get_max_zoom_level()");
-       is($oam->get_projection, $oam->{projection}, "get_projection()");
+       is($oam->get_id, Champlain::MapSourceFactory->OAM, "get_id()");
+       is($oam->get_name, 'OpenAerialMap', "get_name()");
+       is($oam->get_license, "(CC) BY 3.0 OpenAerialMap contributors", "get_license()");
+       is($oam->get_license_uri, 'http://creativecommons.org/licenses/by/3.0/', "get_license_uri()");
+       is($oam->get_min_zoom_level, 0, "get_min_zoom_level()");
+       is($oam->get_max_zoom_level, 17, "get_max_zoom_level()");
+       is($oam->get_projection, 'mercator', "get_projection()");
        
        
        # Setters
index 6b09a18822613ba2ae143b6c90ae72312f911ca7..ef73cf74d5c19846d38833880c5d84fa48a2f8c5 100644 (file)
@@ -88,36 +88,6 @@ champlain_map_source_factory_register (ChamplainMapSourceFactory *factory, SV *s
        OUTPUT:
                RETVAL
 
-/**
- * Provide nice accessors to the data members of the struct.
- */
-SV*
-id (ChamplainMapSourceDesc *desc)
-       ALIAS:
-               Champlain::MapSourceDesc::name = 1
-               Champlain::MapSourceDesc::license = 2
-               Champlain::MapSourceDesc::license_uri = 3
-               Champlain::MapSourceDesc::min_zoom_level = 4
-               Champlain::MapSourceDesc::max_zoom_level = 5
-               Champlain::MapSourceDesc::projection = 6
-
-       CODE:
-               switch (ix) {
-                       case 0: RETVAL = newSVGChar(desc->id); break;
-                       case 1: RETVAL = newSVGChar(desc->name); break;
-                       case 2: RETVAL = newSVGChar(desc->license); break;
-                       case 3: RETVAL = newSVGChar(desc->license_uri); break;
-                       case 4: RETVAL = newSViv(desc->min_zoom_level); break;
-                       case 5: RETVAL = newSViv(desc->max_zoom_level); break;
-                       case 6: RETVAL = newSVChamplainMapProjection(desc->projection); break;
-                       default:
-                               RETVAL = &PL_sv_undef;
-                               g_assert_not_reached ();
-               }
-
-       OUTPUT:
-               RETVAL
-
 
 const gchar*
 OSM_MAPNIK (class)