From 3b50bc9c143d55dbbbb47b0250d996a6c70c1d40 Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Shardiwal Date: Mon, 9 Jun 2014 21:19:04 +0530 Subject: [PATCH 1/2] Used Moo instead Moose, will help in performance. --- Makefile.PL | 6 +++--- lib/Math/Function/Interpolator.pm | 11 ++++++----- lib/Math/Function/Interpolator/Cubic.pm | 14 ++++++++------ lib/Math/Function/Interpolator/Linear.pm | 9 ++++++--- lib/Math/Function/Interpolator/Quadratic.pm | 7 +++++-- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 1ac3cbf..4196a40 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -16,9 +16,9 @@ WriteMakefile( }, BUILD_REQUIRES => { 'Test::More' => 0, - 'Moose' => 0, - 'Moose::Role' => 0, - 'MooseX::Traits' => 0, + 'Moo' => 0, + 'Moo::Role' => 0, + 'MooX::Traits' => 0, 'Module::Runtime' => 0, 'Module::Pluggable' => 0, 'Carp' => 0, diff --git a/lib/Math/Function/Interpolator.pm b/lib/Math/Function/Interpolator.pm index a2142a4..9d9b22f 100644 --- a/lib/Math/Function/Interpolator.pm +++ b/lib/Math/Function/Interpolator.pm @@ -4,8 +4,8 @@ use 5.006; use strict; use warnings FATAL => 'all'; -use Moose; -with qw(MooseX::Traits); +use Moo; +with qw(MooX::Traits); use Carp qw(confess); use Scalar::Util qw(looks_like_number); @@ -13,12 +13,11 @@ use Module::Runtime; use Module::Pluggable sub_name => 'interpolate_methods', search_path => ['Math::Function::Interpolator'], - ; +; # Automatically load all interpolate methods has 'interpolate_classes' => ( is => 'ro', - isa => 'Bool', lazy => 1, default => sub { my ($self) = @_; @@ -32,7 +31,9 @@ has 'interpolate_classes' => ( has points => ( is => 'ro', - isa => 'HashRef', + isa => sub { + die "Points $_[0] shold be hash" unless ref $_[0] eq 'HASH'; + }, required => 1, ); diff --git a/lib/Math/Function/Interpolator/Cubic.pm b/lib/Math/Function/Interpolator/Cubic.pm index 5cf1648..e6d6ac6 100644 --- a/lib/Math/Function/Interpolator/Cubic.pm +++ b/lib/Math/Function/Interpolator/Cubic.pm @@ -6,7 +6,7 @@ use warnings FATAL => 'all'; our $VERSION = '0.01'; -use Moose::Role; +use Moo::Role; use Carp qw(confess); use List::MoreUtils qw(pairwise indexes); @@ -15,7 +15,10 @@ use Scalar::Util qw(looks_like_number); has 'interpolate' => ( is => 'ro', - isa => 'Math::Function::Interpolator', + isa => sub { + die "Must be Interpolate class" + unless ref $_[0] eq 'Math::Function::Interpolator'; + }, required => 1 ); @@ -26,14 +29,14 @@ has _sorted_Xs => ( ); sub _build__sorted_Xs { - my $self = shift; + my ($self) = @_; return [ sort { $a <=> $b } keys %{ $self->interpolate->points } ]; } has _spline_points => ( is => 'ro', - init_arg => undef, - lazy_build => 1, + lazy => 1, + builder => '_build__spline_points', ); sub _build__spline_points { @@ -91,7 +94,6 @@ sub _extrapolate_spline { } # Returns the interpolated_y given point_x and a minimum of 5 data points - sub do_calculation { my ( $self, $x ) = @_; diff --git a/lib/Math/Function/Interpolator/Linear.pm b/lib/Math/Function/Interpolator/Linear.pm index b5d0ff9..ae39fc8 100644 --- a/lib/Math/Function/Interpolator/Linear.pm +++ b/lib/Math/Function/Interpolator/Linear.pm @@ -6,14 +6,17 @@ use warnings FATAL => 'all'; our $VERSION = '0.01'; -use Moose::Role; - +use Moo::Role; +use Carp qw(confess); use Number::Closest::XS qw(find_closest_numbers_around); use Scalar::Util qw(looks_like_number); has 'interpolate' => ( is => 'ro', - isa => 'Math::Function::Interpolator', + isa => sub { + die "Must be Interpolate class" + unless ref $_[0] eq 'Math::Function::Interpolator'; + }, required => 1 ); diff --git a/lib/Math/Function/Interpolator/Quadratic.pm b/lib/Math/Function/Interpolator/Quadratic.pm index 2e7ff4c..e62a2d5 100644 --- a/lib/Math/Function/Interpolator/Quadratic.pm +++ b/lib/Math/Function/Interpolator/Quadratic.pm @@ -6,7 +6,7 @@ use warnings FATAL => 'all'; our $VERSION = '0.01'; -use Moose::Role; +use Moo::Role; use Carp qw(confess); use List::MoreUtils qw(pairwise indexes); @@ -19,7 +19,10 @@ use Try::Tiny; has 'interpolate' => ( is => 'ro', - isa => 'Math::Function::Interpolator', + isa => sub { + die "Must be Interpolate class" + unless ref $_[0] eq 'Math::Function::Interpolator'; + }, required => 1 ); From 49063bc972077d157422b22770abfdd693226e1d Mon Sep 17 00:00:00 2001 From: Rakesh Kumar Shardiwal Date: Mon, 9 Jun 2014 21:21:13 +0530 Subject: [PATCH 2/2] Indentation fixes --- lib/Math/Function/Interpolator/Cubic.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/Math/Function/Interpolator/Cubic.pm b/lib/Math/Function/Interpolator/Cubic.pm index e6d6ac6..a20d863 100644 --- a/lib/Math/Function/Interpolator/Cubic.pm +++ b/lib/Math/Function/Interpolator/Cubic.pm @@ -47,11 +47,10 @@ sub _build__spline_points { my @Ys = map { $points_ref->{$_} } @$Xs; # First element is 0 - # Second derivative of the Y's + # Second derivative of the Ys my @y_2derivative = (0); - - my @u = (0); - my $counter = @$Xs - 2; + my @u = (0); + my $counter = @$Xs - 2; for my $i ( 1 .. $counter ) { my $sig =