App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Series.pm view on Meta::CPAN
return 0;
}
if (defined $values->[$i]) {
$n--;
if ($n <= 0) {
### find_before() found: $i
return $i;
}
}
}
}
}
# return pos where there's a value somwhere $pos > $after, or $after if no more
sub find_after {
my ($self, $after, $n) = @_;
### Series find_after(): "$after n=".($n//'undef')
if ($n <= 0) { return $after; } # asking for no points after
my $values = $self->values_array;
my $hi = $self->hi;
my $chunk = $n;
my $i = $after + 1;
$i = max ($i, 0);
for (;;) {
$chunk *= 2;
my $post = $i + $chunk;
$self->fill ($i, $post);
for ( ; $i <= $post; $i++) {
if ($i > $hi) { return $hi; }
if (defined $values->[$i]) {
$n--;
if ($n <= 0) {
### find_after() found: $i
return $i;
}
}
}
}
}
#------------------------------------------------------------------------------
sub AUTOLOAD {
our $AUTOLOAD;
### Series AUTOLOAD $AUTOLOAD
my $name = $AUTOLOAD;
$name =~ s/(.*):://;
if (my $subr = __PACKAGE__->can($name)) {
{ no strict; *$name = $subr; }
goto &$subr;
}
croak "App::Chart::Series unknown function '$name'";
}
sub can {
my ($self_or_class, $name) = @_;
### Series can(): "$self_or_class '$name'"
return $self_or_class->SUPER::can($name) || do {
if ($name =~ /^GT_/p) {
require App::Chart::Series::GT;
my $type = "I:${^POSTMATCH}";
return sub { App::Chart::Series::GT->new ($type, @_) };
}
if ($name =~ /^TA_/p) {
require App::Chart::Series::TA;
my $type = ${^POSTMATCH};
return sub { App::Chart::Series::TA->new ($type, @_) };
}
require Module::Util;
my $class = "App::Chart::Series::Derived::\u$name";
Module::Util::find_installed($class)
|| return undef; # no such plugin
# if (DEBUG) { print " func $name class $class\n";
# if (eval { Module::Load::load ($class); 1 }) {
# no strict 'refs';
# print " loads ok, new() is ", \&{"${class}::new"}, "\n";
# } else {
# print " didn't load -- $@\n";
# }
# }
require Module::Load;
Module::Load::load ($class);
return sub { $class->new (@_) };
};
}
# avoid going through AUTOLOAD for destroy
sub DESTROY {
}
use overload
'0+' => sub { croak 'Cannot use App::Chart::Series as a number' },
'bool' => sub { 1 },
'!' => sub { 0 },
'""' => sub { $_[0] },
'@{}' => sub { $_[0]->fill(0,$_[0]->hi); $_[0]->values_array },
'+' => \&_overload_add,
'-' => \&sub,
'*' => \&_overload_mul,
'/' => \&div,
'neg' => \&neg,
'**' => \&pow,
'abs' => \&abs,
'cos' => \&cos,
'exp' => \&exp,
'int' => \&int,
'log' => \&log,
'sin' => \&sin,
'sqrt' => \&sqrt;
sub _func {
my ($series, $subr) = @_;
require App::Chart::Series::Func;
return App::Chart::Series::Func->new ($series, $subr);
}
( run in 0.529 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )