It's quite hard to write cross-platform CPAN modules, especially when you use XS to interface with C libraries. Luckily, CPAN Testers tests your modules on many platforms for you. Come see how CPAN Testers helped me to create a fully portable module.
Presented at YAPC::Europe 2011.
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
How CPAN Testers helped me improve my module
1. How CPAN Testers helped me
improve my module
It’s quite hard to write cross-platform CPAN
modules, especially when you use XS to interface
with C libraries. Luckily, CPAN Testers tests your
modules on many platforms for you. Come see
how CPAN Testers helped me to create a fully
portable module.
Léon Brocard
YAPC::Europe
2. Who went to. . .
Barbie’s talk “Smoking e Onion — Tales of CPAN
Testers”
4. Me
Léon Brocard
French, live in London
Like food
Like the colour orange
Founded Amsterdam.pm, Bath.pm, Croydon.pm
Ex-leader of London.pm
Started YAPC::Europe
Looking for employment
Perl hacker
15. Simple API for XML
my $b = XML::LibXML::SAX::Builder->new();
$b->start_document;
$b->start_element( { Name => ’number’ } );
$b->characters( { Data => ’3.141’ } );
$b->end_element( { Name => ’number’ } );
$b->end_document;
say $b->result->toString;
# generates:
<?xml version="1.0"?>
<number>3.141</number>
16. Yet Another JSON Library
“YAJL is a small event-driven (SAX-style) JSON
parser written in ANSI C, and a small validating
JSON generator”
http://lloyd.github.com/yajl/
18. A dream
my $generator = JSON::YAJL::Generator->new();
$generator->map_open();
$generator->string("number");
$generator->number("3.141");
$generator->map_close();
say $generator->get_buf;
# {"number":3.141}
19. Wait, C?
XS – eXternal Subroutine
h xs -x
SWIG – Simpli ed Wrapper and Interface Generator
FFI – Foreign Function Interface
20. Hack hack hack
Perl is written in C with macros
perlguts — Introduction to the Perl API
perlxs — XS language reference manual
perlxstut — Tutorial for writing XSUBs
perlport — Writing portable Perl
Works on my machine, so ship it
. Mon Apr : : CEST
21. CPAN Testers
CPAN Testers is an e ort to set up a Quality
Assurance (QA) team for CPAN modules.
e objective of the group is to test as many of the
distributions on CPAN as possible, on as many
platforms as possible.
e ultimate goal is to improve the portability of the
distributions on CPAN, and provide good feedback
to the authors.
22. Volunteers
Volunteers testing recent CPAN uploads
On a variety of operating systems
On a variety of platforms
On a variety of Perl versions
23.
24. e subject
From: Andreas J. Konig (ANDK)
Subject: FAIL JSON-YAJL-0.01 v5.8.7 GNU/Linux
Date: 2011-04-11T10:25:15Z
This distribution has been tested as part of
the CPAN Testers project, supporting the
Perl programming language. See
http://wiki.cpantesters.org/ for more
information or email questions to
cpan-testers-discuss@perl.org
25. Grades
PASS distribution built and tested correctly
FAIL distribution failed to test correctly
UNKNOWN distribution failed to build, had no
test suite or outcome was inconclu-
sive
NA distribution is not applicable to this
platform and/or version of Perl
26. Preamble
Dear Leon Brocard,
This is a computer-generated report for
JSON-YAJL-0.01 on perl 5.8.7, created by
CPAN-Reporter-1.1902.
Thank you for uploading your work to CPAN.
However, there was a problem testing your
distribution.
If you think this report is invalid, please
consult the CPAN Testers Wiki for suggestions
on how to avoid getting FAIL reports for
missing library or binary dependencies,
unsupported operating systems, and so on:
27. Tester comments
This report is from an automated smoke
testing program and was not reviewed by
a human for accuracy.
28. Program output
Output from ’./Build test’:
t/pod.t ..... ok
Can’t load ’/home/sand/.cpan/build/JSON-YAJL-0.01-vYmtrJ/blib/arch/auto/JSON/YAJL/Generator/G
at /home/sand/.cpan/build/JSON-YAJL-0.01-vYmtrJ/blib/lib/JSON/YAJL.pm line 4
Compilation failed in require at /home/sand/.cpan/build/JSON-YAJL-0.01-vYmtrJ/blib/lib/JSON/Y
BEGIN failed--compilation aborted at /home/sand/.cpan/build/JSON-YAJL-0.01-vYmtrJ/blib/lib/JS
Compilation failed in require at t/simple.t line 5.
BEGIN failed--compilation aborted at t/simple.t line 5.
t/simple.t ..
Dubious, test returned 9 (wstat 2304, 0x900)
No subtests run
Test Summary Report
-------------------
t/simple.t (Wstat: 2304 Tests: 0 Failed: 0)
Non-zero exit status: 9
Parse errors: No plan found in TAP output
Files=2, Tests=2, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.07 cusr 0.02 csys = 0.12 CPU)
Result: FAIL
Failed 1/2 test programs. 0/2 subtests failed.
29. Also
Prerequisites (and version numbers)
Environment variables (PATH, SHELL etc.)
Perl special variables and OS-speci c diagnostics
Perl module toolchain versions installed
37. e error
Can’t load
‘/home/sand/.cpan/build/JSON-YAJL- . -vYmtrJ-
/blib/arch/auto/JSON/YAJL/Generator/Generator.so’
for module JSON::YAJL::Generator:
/home/sand/.cpan/build/JSON-YAJL- . -vYmtrJ-
/blib/arch/auto/JSON/YAJL/Generator/Generator.so:
unde ned symbol: newSVpvn_utf at
/usr/local/perl- . . -threaded/lib/ . . /x _ -linux-
thread-multi-ld/DynaLoader.pm line
.
38. perlapi says
Creates a new SV and copies a string into it. If utf is
true, calls "SvUTF _on" on the new SV.
SV* newSVpvn_utf8(NULLOK const
char* s, STRLEN len, U32 utf8)
Introduced in . , as pointed out by Andreas J. König.
39. Devel::PPPort - Perl/Pollution/Portability
Perl’s API has changed over time, gaining new
features, new functions, increasing its exibility, and
reducing the impact on the C namespace
environment (reduced pollution). e header le
written by this module, typically ppport.h, attempts
to bring some of the newer Perl API features to older
versions of Perl, so that you can worry less about
keeping track of old releases, but users can still reap
the bene t.
44. Release . ( )
do not include stdint.h as we do not need it
. Tue Apr : : CEST
45.
46. Release .
got: . expected: .
Stop using . for testing oats
What Every Computer Scientist Should Know About
Floating-Point Arithmetic — David Goldberg
47. Release . ( )
symbol isinf: referenced symbol not found
#if defined (__SVR4) && defined (__sun)
#ifndef isinf
#include
#define isinf(x) (!finite((x)) && (x)==(x))
#endif
#endif
48. Release . ( )
Error: ’const char *’ not in typemap in Generator.xs,
line
add const char * to the typemap to support Perl .
49. Release . ( )
throw exceptions upon YAJL error states
. Wed Apr : : CEST
50.
51. Release .
Half the tests failed!
error: too few arguments to function ’Perl_croak’
use aTHX_ when Perl_croak-ing to work on threaded
Perls
Perl_croak(aTHX_ "YAJL: Keys must be strings");
52. Release . ( )
expecting: Regexp ((?-xism:Invalid number)) found:
YAJL: Keys must be strings
Only test inf and nan on Perl . . and later
. u Apr : : CEST
53.
54. Release .
x minor documentation typo
don’t test inf and nan under MSWin
add an interface to the parser
take advantage of typemaps and declarations to
minimize XS code
. Sat Apr : : CEST
55.
56. Release .
link to YAJL website, as pointed out by Olivier
Mengué
add homepage, repository and bugtracker
distribution metadata
add LICENSE le
add a SAX builder example
add a tokenising example
add a tokenising, parsing with Marpa example
improved documentation, clearer tests
. Mon Apr : : CEST
57.
58. Release .
update to YAJL . .
. Mon Jun : : BST
59.
60. Release .
don’t test inf and nan under MirOS BSD
work around not nding isinf under Solaris
work around missing sprintf_s under Windows
. Wed Jul : : BST
61.
62. Release .
work aroud the fact that win mingw/gcc doesn’t
have sprintf_s (for Strawberry Perl)
move dSP to top of callback_call to compile under
Microso Visual Studio .
. u Aug : : BST
63.
64. Microso Visual C++ does not support long long:
yajlyajl_parse.h(77) : error C2632: ’long’
followed by ’long’ is illegal
yajlyajl_parser.h(74) : error C2632: ’long’
followed by ’long’ is illegal
66. How to become a CPAN Tester
CPAN::Reporter
http://wiki.cpantesters.org/
67. CPAN Testers Leaderboard
st , , Chris Williams (BINGOS)
nd , , Andreas J. König (ANDK)
rd , Dan Collins (DCOLLINS)
...
th , Léon Brocard (LBROCARD)
68. Summary
, test reports
perls
platforms
All helping to make CPAN modules more portable
69. On next at :
Liel¯ z¯le: Perl Lists, Arrays, and Hashes vivi ed:
a a
lazy, in nite, at, slurpy, typed, bound, and LoL’d,
Patrick Michaud
Auditorija : Encryption on the Web for everyone,
Lars D
Auditorija : Terms of endearment — the
ElasticSearch query language explained, Clinton
Gormley
Auditorija : Perlude: a taste of haskell in perl, Marc
Chantreux