From 0feef890b11479681b5e731e200ace0adc4c0330 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 13 Mar 2013 01:29:45 +0100 Subject: [PATCH] Use Class::XSAccessor --- Build.PL | 1 + lib/Slic3r/Config.pm | 6 +++++- lib/Slic3r/Surface.pm | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Build.PL b/Build.PL index b4bed05ce..b8921a8c0 100644 --- a/Build.PL +++ b/Build.PL @@ -26,6 +26,7 @@ my $build = Module::Build->new( 'IO::Scalar' => '0.10', }, recommends => { + 'Class::XSAccessor' => '0', 'Growl::GNTP' => '0.15', 'Net::DBus' => '0', 'XML::SAX::ExpatXS' => '0', diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 5bd91a288..0017d9257 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -991,7 +991,11 @@ END }; # generate accessors -{ +if (eval "use Class::XSAccessor; 1") { + Class::XSAccessor->import( + getters => { map { $_ => $_ } keys %$Options }, + ); +} else { no strict 'refs'; for my $opt_key (keys %$Options) { *{$opt_key} = sub { $_[0]{$opt_key} }; diff --git a/lib/Slic3r/Surface.pm b/lib/Slic3r/Surface.pm index efa0f46a9..2864a8643 100644 --- a/lib/Slic3r/Surface.pm +++ b/lib/Slic3r/Surface.pm @@ -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 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 sub encloses_point { $_[0]->expolygon->encloses_point } sub lines { $_[0]->expolygon->lines }