diff options
Diffstat (limited to 'lib/Data/QRCode/Result.pm')
-rw-r--r-- | lib/Data/QRCode/Result.pm | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/Data/QRCode/Result.pm b/lib/Data/QRCode/Result.pm new file mode 100644 index 0000000..10c79d0 --- /dev/null +++ b/lib/Data/QRCode/Result.pm @@ -0,0 +1,63 @@ +package Data::QRCode::Result; +use strict; +use warnings; +# ABSTRACT: qrcodes in C +# VERSION +use Data::QRCode::Result::Inline with => 'Alien::QREncode'; +use Data::QRCode::Result::Inline C => ( + 'DATA', + autowrap => 1, + typemaps => 'typemap', +); + +sub new { + my ($class, $input) = @_; + my $self = QRcode_encodeInput($input); + bless $self, $class; + return $self; +} + +sub _data_hash { + my ($value) = @_; + + 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, + }; +} + +sub data_at { + my ($self,$x,$y) = @_; + my $width = $self->width; + if ($x < 0 or $x >= $width or $y < 0 or $y >= $width) { + return; + } + return _data_hash($self->_data_at($x,$y)); +} + +1; + +__DATA__ +__C__ + +QRcode *QRcode_encodeInput(QRinput *input); + +void DESTROY(QRcode *qrcode) { QRcode_free(qrcode); } + +int version(QRcode* self) { + return self->version; +} + +int width(QRcode* self) { + return self->width; +} + +int _data_at(QRcode* self, int x, int y) { + return self->data[x+y*self->width]; +} |