CXC-PDL-Bin1D

 view release on metacpan or  search on metacpan

lib/CXC/PDL/Bin1D.pd  view on Meta::CPAN

use warnings;
use version;

use IO::File;
use File::Spec::Functions qw[ catfile ];

use lib 'lib';

use CXC::PDL::Bin1D::Utils '_bitflags';
use PDL ();
use PDL::Bad;

use File::Basename qw[ fileparse ];

# this file is executed directly by Perl, so $0 will be our filename,
# which allows us to find the parent directory.
use constant LIBDIR => ( fileparse( $0 ) )[1];

use PDL::Types qw[ typefld ];


# later versions of PDL define index types:
#  'PDL_Indx' (as a C typedef) and 'indx' for signatures
# for backwards compatibility, support long as well as the others

my ( $IndexParsType, $IndexCType ) = do {

    my $type = eval { typefld( 'PDL_IND', 'ctype' ); 1 } ? 'PDL_IND' : 'PDL_L';

    map { typefld( $type, $_ ) } qw( ppforcetype ctype );
};

our $VERSION = '0.28';
pp_setversion( $VERSION );

{
    package CXC::PDL::Bin1D;

    use Text::Template::LocalVars;
    use File::Spec::Functions qw[ catfile ];

    use Exporter 'import';
    ## no critic (Modules::ProhibitAutomaticExportation)
    our @EXPORT = qw< fill_in fill_in_string >;

    # this code must be compiled in the template variable package
    sub init_fill_package {

        Text::Template::LocalVars->new(
            type       => 'string',
            delimiters => [qw( <% %>  )],
            source     => <<'EOS',
             *fill_in             = \&<% $PACKAGE %>::fill_in;
             *fill_in_string      = \&<% $PACKAGE %>::fill_in_string;
EOS
        )->fill_in( hash => { PACKAGE => __PACKAGE__ } );

    }

    # fill in templates using Text::Template::LocalVars.  This routine
    # is also imported into all of the template fragments.
    sub fill_in {

        my ( $type, $src ) = ( shift, shift );

        $src = catfile( ::LIBDIR, $src )
          if lc $type eq 'file' && $src !~ m{^[./]}s;

        my $tpl = Text::Template::LocalVars->new(
            type       => $type,
            source     => $src,
            delimiters => [qw( <% %>  )],
            broken     => sub { my %args = @_; die $args{error}; },
            prepend    => init_fill_package(),
        );

        die $Text::Template::ERROR unless defined $tpl;

        # by default, localize the variable packages, and insert the last one
        # in the call chain if not explicitly specified.
        my %args = ( localize => 1, trackpkgvars => 1, @_ );

        my $hash = $args{hash} ||= {};
        $hash->{PDL_Indx} = $IndexCType;

        my $txt;
        eval {
            $txt = $tpl->fill_in( %args );
            die unless defined $txt;
            1;
        }
          or die defined $Text::Template::LocalVars::ERROR
          ? $Text::Template::LocalVars::ERROR
          : $@;

        return $txt;
    }

    sub fill_in_string {

        unshift @_, 'string';
        goto \&fill_in;

    }

}

CXC::PDL::Bin1D->import;


my %CONSTANTS = (
    BIN_ARG => {
        _bitflags( qw[
              BIN_ARG_HAVE_ERROR
              BIN_ARG_HAVE_WEIGHT
              BIN_ARG_SET_BAD
              BIN_ARG_FOLD
              BIN_ARG_HAVE_WIDTH
              BIN_ARG_ERROR_SDEV
              BIN_ARG_ERROR_POISSON
              BIN_ARG_ERROR_RSS



( run in 1.148 second using v1.01-cache-2.11-cpan-b16cb0d3907 )