diff options
author | dakkar <dakkar@thenautilus.net> | 2016-10-23 18:34:19 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2016-10-23 18:34:19 +0100 |
commit | c9129ed66317abfcd8e7689ef77199bd86bf5309 (patch) | |
tree | a3de54e37250d3a2a507aa7d1806f3467993b421 /lib/Data/QRCode.pm | |
parent | first stab (diff) | |
download | Data-QRCode-c9129ed66317abfcd8e7689ef77199bd86bf5309.tar.gz Data-QRCode-c9129ed66317abfcd8e7689ef77199bd86bf5309.tar.bz2 Data-QRCode-c9129ed66317abfcd8e7689ef77199bd86bf5309.zip |
works
Diffstat (limited to 'lib/Data/QRCode.pm')
-rw-r--r-- | lib/Data/QRCode.pm | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/Data/QRCode.pm b/lib/Data/QRCode.pm new file mode 100644 index 0000000..680e251 --- /dev/null +++ b/lib/Data/QRCode.pm @@ -0,0 +1,46 @@ +package Data::QRCode; +use strict; +use warnings; +# ABSTRACT: qrcodes in C +# VERSION +use Data::QRCode::XS; + +my %levels = ( + L => Data::QRCode::XS::ECLEVEL_L(), + M => Data::QRCode::XS::ECLEVEL_M(), + Q => Data::QRCode::XS::ECLEVEL_Q(), + H => Data::QRCode::XS::ECLEVEL_H(), +); + +sub new { + my ($class, $data, $level, $version) = @_; + $version ||= 0; + $level = $levels{uc $level} || Data::QRCode::XS::ECLEVEL_M(); + return Data::QRCode::XS::_build($class,$data,$level,$version); +} + +sub width { Data::QRCode::XS::width(@_) } + +sub version { Data::QRCode::XS::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::QRCode::XS::_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; |