I am taking my first steps into XS in order to wrap a C++ library. The library implements a rather specialized compression algorithm and can be found here. I've managed to implement and successfully test the bindings using ExtUtils::XSpp. However, right now the classes and methods are just bare stubs to the C++ counterparts, and I would like to be able to make the interface more "perlish" - e.g. instead of writing

my $reader = Compress::DSRC::Archive->new; my $seq = Compress::DSRC::FastqRecord->new; while ($reader->next_seq($seq)) { # do something with $seq }
I would like to write:
my $reader = Compress::DSRC::Archive->new; while (my $seq = $reader->next_seq) { # do something with $seq }

I have a lot to learn about XS and this may turn out to be a simple problem, but I would appreciate any examples or pointers to the relevant documentation (especially examples). Since this is a matter of interface rather than function it is not a high priority, but it would be nice to make the interface consistent with the most typical perl syntax. Thanks in advance for any help. A truncated snippet of my *.xsp file is below.

#include "Globals.h" #include "FastqRecord.h" #include "FastqFile.h" #include "DsrcModule.h" #include "DsrcArchive.h" #include "ns.h" %module{Compress::DSRC}; %loadplugin{feature::default_xs_typemap}; %name{Compress::DSRC::FastqRecord} class FastqRecord { %name{new} FastqRecord(); ~FastqRecord(); std::string tag %get %set; std::string sequence %get %set; std::string plus %get %set; std::string quality %get %set; }; %name{Compress::DSRC::Archive} class DsrcArchive { %name{new} DsrcArchive(); ~DsrcArchive(); %name{start_decompress} void StartDecompress(std::string& filename +_); %name{next_seq} bool ReadNextRecord(FastqRecord& rec_); %name{finish_decompress} void FinishDecompress(); [..truncated...] };

In reply to "Perlifying" an XSpp method by jdv

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.