Hello all, I got stuck when I was trying to call a subroutine in .xs file. run h2xs -n Parser... modify Parser.pm:
################################### #!/usr/local/bin/perl package Parser; use 5.008007; use strict; use warnings; require Exporter; require DynaLoader; our @ISA = qw(DynaLoader Exporter); our %EXPORT_TAGS = ( 'all' => [ qw() ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw(); our $VERSION = '1.261'; bootstrap Parser $VERSION; # Preloaded methods go here. ########################################################## sub new { my $class = shift; $class = ref $class if ref $class; my $self = { strip_autos=>0, @_}; bless $self, $class; return $self; } sub read { my $self = shift; my %param = (@_); if (!-r $param{filename}) { print "%Error: file not found: $param{ +filename}, stopped";} $self->_read_xs($param{filename}, $param{strip_autos}||$self->{str +ip_autos});## error comes } ... #In Parser.XS: # sub _read_xs {class} # sub filename {class} # sub lineno {class} ...
Parser.xs (snippet) ...
int _read_xs (CLASS, filename, strip_autos) SV *CLASS char *filename int strip_autos PROTOTYPE: $$$ CODE: { static int/*bool*/ in_parser = 0; if (!SvROK(CLASS)) { in_parser = 0; croak (" Parser::read() not called as class member") ; } if (!filename) { in_parser = 0; croak (" Parser::read() filename=> parameter not passed") ; } if (in_parser) { croak (" Parser::read() called recursively") ; } in_parser = 1; scparse_init (CLASS, filename, strip_autos) ; if (!sclex_open (filename)) { in_parser = 0; croak (" Parser::read() file not found") ; } scgrammerparse(); fclose (sclexin); /* Emit final tokens */ scparser_EmitPrefix (); if (scParserState.errors) { in_parser = 0; croak (" Parser::read() detected parse errors"); } in_parser = 0; RETVAL = 1; } OUTPUT: RETVAL
... a test file named Trialparser.pl is showed below:
#! /usr/local/bin/perl use ExtUtils::testlib; package Trialparser; use Parser; @ISA = qw(Parser); package main; my $sp = Trialparser->new(); $sp->read (filename =>'ExParse.sp');
There was no problem with running perl makefile.pl, make, make test, make install, but an error came out when I trying "perl Trialparser.pl":
Can't locate auto/Trialparser/class.al in @INC (@INC contains: /cygdri +ve/d/parser/blib/arch /cygdrive/d/parser/blib/lib /usr/lib/perl5/5.8/ +cygwin /usr/lib/perl5/5.8 /usr/lib/perl5/site_perl/5.8/cygwin /usr/li +b/perl5/site_perl/5.8 /usr/lib/perl5/vendor_perl/5.8/cygwin /usr/lib/ +perl5/vendor_perl/5.8 .) at /cygdrive/d/parser/blib/lib/Parser.pm lin +e 51
Anyone can help me with me? what does class.al stand for? Any suggestion is welcome, thanks in advance!!!!!

In reply to An error in using XS by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.