From ea6a8a0658d1ba354a43d57f626c04951ac48e98 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 10 Nov 2016 12:49:46 +0000 Subject: try using more magic --- lib/Data/QRCode/XS.pm | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/lib/Data/QRCode/XS.pm b/lib/Data/QRCode/XS.pm index f46cba6..aa8597a 100644 --- a/lib/Data/QRCode/XS.pm +++ b/lib/Data/QRCode/XS.pm @@ -3,52 +3,45 @@ use strict; use warnings; # ABSTRACT: qrcodes in C # VERSION -use Alien::QREncode; -use Data::QRCode::XS::Inline C => ( ); +use Data::QRCode::XS::Inline with => 'Alien::QREncode'; +use Data::QRCode::XS::Inline C => ( + 'DATA', + autowrap => 1, + typemaps => 'typemap', +); 1; __DATA__ - __C__ -#include "qrencode.h" - int ECLEVEL_L() { return QR_ECLEVEL_L; } int ECLEVEL_M() { return QR_ECLEVEL_M; } int ECLEVEL_Q() { return QR_ECLEVEL_Q; } int ECLEVEL_H() { return QR_ECLEVEL_H; } -SV* _build(const char* class, SV* data, int level, int version ) { +#define CLASS "Data::QRCode" + +QRcode* _build(const char* class, SV* data, int level, int version ) { unsigned char * str; STRLEN len; - SV * qrsv; SV* self; - QRcode* qr_code; str = SvPVutf8(data,len); - qr_code = QRcode_encodeData(len,str,version,(QRecLevel)level); - qrsv = newSViv((IV)qr_code); - self = newRV_noinc(qrsv); - sv_bless(self, gv_stashpv(class, GV_ADD)); - SvREADONLY_on(qrsv); - - return self; + return QRcode_encodeData(len,str,version,(QRecLevel)level); } -int version(SV* self) { - return ((QRcode*)SvIV(SvRV(self)))->version; +int version(QRcode* self) { + return self->version; } -int width(SV* self) { - return ((QRcode*)SvIV(SvRV(self)))->width; +int width(QRcode* self) { + return self->width; } -void DESTROY(SV* self) { - QRcode* qr_code = (QRcode*)SvIV(SvRV(self)); - QRcode_free(qr_code); +void DESTROY(QRcode* self) { + QRcode_free(self); } -int _data_at(SV* self, int x, int y) { - QRcode* qr_code = (QRcode*)SvIV(SvRV(self)); - return qr_code->data[x+y*qr_code->width]; +int _data_at(QRcode* self, int x, int y) { + return self->data[x+y*self->width]; } -- cgit v1.2.3