diff options
Diffstat (limited to 'lib/Data/QRCode')
-rw-r--r-- | lib/Data/QRCode/Input.pm | 75 | ||||
-rw-r--r-- | lib/Data/QRCode/XS.pm | 47 |
2 files changed, 75 insertions, 47 deletions
diff --git a/lib/Data/QRCode/Input.pm b/lib/Data/QRCode/Input.pm new file mode 100644 index 0000000..69fd283 --- /dev/null +++ b/lib/Data/QRCode/Input.pm @@ -0,0 +1,75 @@ +package Data::QRCode::Input; +use strict; +use warnings; +# ABSTRACT: qrcodes in C +# VERSION +use Data::QRCode::Input::Inline with => 'Alien::QREncode'; +use Data::QRCode::Input::Inline C => ( + 'DATA', + autowrap => 1, + typemaps => 'typemap', +); + +sub new { + my ($class) = @_; + + my $self = QRinput_new(); + bless $self,$class; + return $self; +} + +sub version { + my $self = shift; + if (@_) { + return QRinput_setVersion($self,shift); + } + else { + return QRinput_getVersion($self); + } +} + +sub error_correction_level { + my $self = shift; + if (@_) { + return QRinput_setErrorCorrectionLevel($self,shift); + } + else { + return QRinput_getErrorCorrectionLevel($self); + } +} + +1; + +__DATA__ +__C__ + +QRecLevel ECLEVEL_L() { return QR_ECLEVEL_L; } +QRecLevel ECLEVEL_M() { return QR_ECLEVEL_M; } +QRecLevel ECLEVEL_Q() { return QR_ECLEVEL_Q; } +QRecLevel ECLEVEL_H() { return QR_ECLEVEL_H; } + +QRencodeMode MODE_NUM() { return QR_MODE_NUM; } +QRencodeMode MODE_AN() { return QR_MODE_AN; } +QRencodeMode MODE_8() { return QR_MODE_8; } +QRencodeMode MODE_KANJI() { return QR_MODE_KANJI; } +QRencodeMode MODE_STRUCTURE() { return QR_MODE_STRUCTURE; } +QRencodeMode MODE_ECI() { return QR_MODE_ECI; } +QRencodeMode MODE_FNC1FIRST() { return QR_MODE_FNC1FIRST; } +QRencodeMode MODE_FNC1SECOND() { return QR_MODE_FNC1SECOND; } + +extern QRinput *QRinput_new(void); +void DESTROY(QRinput *input) { QRinput_free(input); } + +int append(QRinput *input, QRencodeMode mode, SV *data) { + unsigned char * str; + STRLEN len; + + str = SvPVutf8(data,len); + return QRinput_append(input,mode,len,str); +} + +extern int QRinput_getVersion(QRinput *input); +extern int QRinput_setVersion(QRinput *input, int version); + +extern QRecLevel QRinput_getErrorCorrectionLevel(QRinput *input); +extern int QRinput_setErrorCorrectionLevel(QRinput *input, QRecLevel level); diff --git a/lib/Data/QRCode/XS.pm b/lib/Data/QRCode/XS.pm deleted file mode 100644 index aa8597a..0000000 --- a/lib/Data/QRCode/XS.pm +++ /dev/null @@ -1,47 +0,0 @@ -package Data::QRCode::XS; -use strict; -use warnings; -# ABSTRACT: qrcodes in C -# VERSION -use Data::QRCode::XS::Inline with => 'Alien::QREncode'; -use Data::QRCode::XS::Inline C => ( - 'DATA', - autowrap => 1, - typemaps => 'typemap', -); - -1; - -__DATA__ -__C__ - -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; } - -#define CLASS "Data::QRCode" - -QRcode* _build(const char* class, SV* data, int level, int version ) { - unsigned char * str; - STRLEN len; - - str = SvPVutf8(data,len); - return QRcode_encodeData(len,str,version,(QRecLevel)level); -} - -int version(QRcode* self) { - return self->version; -} - -int width(QRcode* self) { - return self->width; -} - -void DESTROY(QRcode* self) { - QRcode_free(self); -} - -int _data_at(QRcode* self, int x, int y) { - return self->data[x+y*self->width]; -} |