summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2016-10-23 18:16:39 +0100
committerdakkar <dakkar@thenautilus.net>2016-10-23 18:16:39 +0100
commit8895c34d1b5dc58355af99cdc7bf0d4216c2bfa0 (patch)
tree40193264e0ce334f04434d124a240ce51fafd0ee
parentadd Pod::Elemental::Transformer::List as authordep (diff)
downloadData-QRCode-8895c34d1b5dc58355af99cdc7bf0d4216c2bfa0.tar.gz
Data-QRCode-8895c34d1b5dc58355af99cdc7bf0d4216c2bfa0.tar.bz2
Data-QRCode-8895c34d1b5dc58355af99cdc7bf0d4216c2bfa0.zip
first stab
-rw-r--r--dist.ini6
-rw-r--r--lib/Data/QRCode/XS.pm85
2 files changed, 90 insertions, 1 deletions
diff --git a/dist.ini b/dist.ini
index 6081f49..5f6eec3 100644
--- a/dist.ini
+++ b/dist.ini
@@ -1,10 +1,14 @@
+name = Data-QRCode
author = Gianni Ceccarelli <dakkar@thenautilus.net>
license = Perl_5
copyright_holder = Gianni Ceccarelli <dakkar@thenautilus.net>
-copyright_year = 2015
+copyright_year = 2016
[GatherDir]
+[InlineModule]
+module = Data::QRCode::XS
+
[PodWeaver]
; authordep Pod::Elemental::Transformer::List
diff --git a/lib/Data/QRCode/XS.pm b/lib/Data/QRCode/XS.pm
new file mode 100644
index 0000000..f42940f
--- /dev/null
+++ b/lib/Data/QRCode/XS.pm
@@ -0,0 +1,85 @@
+package Data::QRCode::XS;
+use strict;
+use warnings;
+# VERSION
+use Alien::QREncode;
+use Data::QRCode::XS::Inline C => ( );
+
+my %levels = (
+ L => ECLEVEL_L,
+ M => ECLEVEL_M,
+ Q => ECLEVEL_Q,
+ H => ECLEVEL_H,
+);
+
+sub new {
+ my ($class, $data, $level, $version) = @_;
+ $version ||= 0;
+ $level = $levels{uc $level} || ECLEVEL_M;
+ return _build($class,$data,$level,$version);
+}
+
+sub data_at {
+ my ($self,$x,$y) = @_;
+ my $width = $self->width;
+ if ($x < 0 or $x >= $width or $y < 0 or $y >= $width) {
+ return;
+ }
+ my $value = _data_at($self,$x,$y);
+
+ return {
+ color => $value & 0x01,
+ in_data => $value & 0x02,
+ in_format => $value & 0x04,
+ in_version => $value & 0x08,
+ in_timing => $value & 0x10,
+ in_alignment => $value & 0x20,
+ in_finder => $value & 0x40,
+ in_misc => $value & 0x80,
+ };
+}
+
+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; }
+
+SV* _build(const char* class, const 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,data,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;
+}
+
+int version(SV* self) {
+ return ((QRcode*)SvIV(SvRV(self)))->version;
+}
+
+int width(SV* self) {
+ return ((QRcode*)SvIV(SvRV(self)))->width;
+}
+
+void DESTROY(SV* self) {
+ QRcode* qr_code = (QRcode*)SvIV(SvRV(self));
+ QRcode_free(qr_code);
+}
+
+int _data_at(SV* self, int x, int y) {
+ QRcode* qr_code = (QRcode*)SvIV(SvRV(self));
+ return qr_code->data[x+y*width];
+}