Use Class::XSAccessor

This commit is contained in:
Alessandro Ranellucci 2013-03-13 01:29:45 +01:00
parent cab51d4581
commit 0feef890b1
3 changed files with 21 additions and 1 deletions

View File

@ -26,6 +26,7 @@ my $build = Module::Build->new(
'IO::Scalar' => '0.10', 'IO::Scalar' => '0.10',
}, },
recommends => { recommends => {
'Class::XSAccessor' => '0',
'Growl::GNTP' => '0.15', 'Growl::GNTP' => '0.15',
'Net::DBus' => '0', 'Net::DBus' => '0',
'XML::SAX::ExpatXS' => '0', 'XML::SAX::ExpatXS' => '0',

View File

@ -991,7 +991,11 @@ END
}; };
# generate accessors # generate accessors
{ if (eval "use Class::XSAccessor; 1") {
Class::XSAccessor->import(
getters => { map { $_ => $_ } keys %$Options },
);
} else {
no strict 'refs'; no strict 'refs';
for my $opt_key (keys %$Options) { for my $opt_key (keys %$Options) {
*{$opt_key} = sub { $_[0]{$opt_key} }; *{$opt_key} = sub { $_[0]{$opt_key} };

View File

@ -38,6 +38,21 @@ sub depth_layers { $_[0][S_DEPTH_LAYERS] } # this integer represents the thic
sub bridge_angle { $_[0][S_BRIDGE_ANGLE] = $_[1] if defined $_[1]; $_[0][S_BRIDGE_ANGLE] } sub bridge_angle { $_[0][S_BRIDGE_ANGLE] = $_[1] if defined $_[1]; $_[0][S_BRIDGE_ANGLE] }
sub extra_perimeters { $_[0][S_EXTRA_PERIMETERS] = $_[1] if defined $_[1]; $_[0][S_EXTRA_PERIMETERS] } sub extra_perimeters { $_[0][S_EXTRA_PERIMETERS] = $_[1] if defined $_[1]; $_[0][S_EXTRA_PERIMETERS] }
if (eval "use Class::XSAccessor::Array; 1") {
Class::XSAccessor::Array->import(
getters => {
expolygon => S_EXPOLYGON,
},
accessors => {
surface_type => S_SURFACE_TYPE,
depth_layers => S_DEPTH_LAYERS,
bridge_angle => S_BRIDGE_ANGLE,
extra_perimeters => S_EXTRA_PERIMETERS,
},
replace => 1,
);
}
# delegate handles # delegate handles
sub encloses_point { $_[0]->expolygon->encloses_point } sub encloses_point { $_[0]->expolygon->encloses_point }
sub lines { $_[0]->expolygon->lines } sub lines { $_[0]->expolygon->lines }