=head1 NAME

CCL::Parser::Lite - Perl interface for cclapilt

=head1 SYNOPSIS

  use CCL::Parser::Lite;
  my $api=CCL::Parser::Lite->new();
  $api->loadCCLData(\@list);
  # ...

=head1 DESCRIPTION

Perl interface to the cclapilt library, qv.  The interface follows the
cclapilt interface pretty closely, so see that for more details.

This is used internally by the heavy API, and is not intended for
direct use.

Note that the default handle is not supported by this interface: all
accesses are done through the object-style interface, which maps to
the *H calls at the C level.

=head1 AUTHOR

Andy Mortimer

=cut

package CCL::Parser::Lite;

require 5.005_62;
use strict;
use warnings;
use Config;

#require DynaLoader;

#our @ISA = qw(DynaLoader);

our $VERSION = '0.01';

# if we are being called from a program linked against the cclApi
# files, we hope the interface will already be linked in; we try to be
# careful about having two copies, because of issues with memory
# allocated and freed in different DLLs on Windows.  So we implement
# our own bootstrapping, using dynaloader, in case we're being called
# from Perl.
eval {
  bootstrap CCL::Parser::Lite $VERSION;
};
if ($@ =~ m!Can't locate object method "bootstrap"!) {
  # OK, it's not linked in (or it went a bit wrong ...).  Do it
  # ourselves.  If you get errors here and you're not trying to access
  # the API from a standard Perl interpreter, check your xsinit.c.

  # first, check to see if it looks like we're in a standard Perl
  # exec, or one of the Windows cfx5*.exe wrapped scripts.  If not,
  # the stuff should already be linked in.
  if ($^X !~ m!perl[^\\/]*$!o and $^X !~ m!cfx5[^\\/]*$!) {
    warn "Attempting to dynamically load ", __PACKAGE__, 
      " from custom executable $^X.  This shouldn't happen.  ",
        "Check your xsinit.c.";
  }

  my $libdir=$ENV{CFX5_CCLAPI_LIBDIR} || $ENV{CFX5LIBDIR};
  die "CFX5LIBDIR unset, unable to auto-load ", __PACKAGE__
    unless (defined $libdir);
  die "CFX5LIBDIR directory $libdir does not exist, unable to autoload ", __PACKAGE__
    unless -d $libdir;

  my %exts=(
            'MSWin32-x86-perlio' => 'dll',
            'MSWin32-AMD64-perlio' => 'dll',
	    'MSWin32-x64-perlio' => 'dll',
            'MSWin32-x86-multi-thread' => 'dll',
            'MSWin32-x64-multi-thread' => 'dll',
            MSWin32 => 'dll',
            'PA-RISC2.0-LP64' => 'sl',
            hpux => 'sl',
           );
  my $ext=$exts{$Config{archname}} || 'so';
  my $libfile="$libdir/CCL_Parser_Lite.$ext";
  die "$libfile missing, unable to autoload ", __PACKAGE__
    unless -f $libfile;

  require DynaLoader;
  my $lib=DynaLoader::dl_load_file($libfile, DynaLoader::dl_load_flags());
  die "Error loading library $libfile: ", DynaLoader::dl_error()
    unless $lib;

  my $sym=DynaLoader::dl_find_symbol($lib, 'boot_CCL__Parser__Lite');
  die "Error finding bootstrap routine boot_CCL__Parser__Lite in $libfile: ", DynaLoader::dl_error()
    unless $sym;

  DynaLoader::dl_install_xsub(__PACKAGE__ . "::bootstrap", $sym, __FILE__);

  eval {
    bootstrap CCL::Parser::Lite $VERSION;
  };
  if ($@) {
    die "Error bootstrapping ", __PACKAGE__, " even after loading the bootstrap routine: $@";
  }
}


=head2 ADDITIONAL FUNCTIONS

=head3 new

Constructor.  Doesn't do much, really, but returns a new API instance
that you can use (internally calls createCCLInstance).

=cut

sub new {
  return NEW();
}

=head2 COPIED FROM HEAVY API

=head3 parseCCLData

Just an alias for loadCCLData

=cut

sub parseCCLData {
  my $self=shift;
  warn "parseCCLData is deprecated, and should now be called as loadCCLData";
  $self->loadCCLData(@_);
}

=head3 getName(string cclPath)

$name=getName(string cclPath)

Given the path to a object or parameter, return the name of the object or parameter.
Returns undef if no such object/param is found.

Argument List :

 string cclPath

Return List:
 string name

=cut

sub getName {
    my ($self,$cclPath) = @_;

    (my $name=$cclPath) =~ s!.*/!!;
    $name =~ s/.*://;
    $name;
}

1;
