QRCode-Encoder

 view release on metacpan or  search on metacpan

lib/QRCode/Encoder/Matrix.pm  view on Meta::CPAN

}

sub bits_iterator ($data) {
   my $n_expanded = length($data->{expanded});
   my $rem = $data->{remainder};
   my $i = 0;
   my @queue;
   return sub {
      if (! @queue) {
         if ($i < $n_expanded) {
            push @queue, split m{}mxs, unpack 'B*', substr($data->{expanded}, $i++, 1);
         }
         else {
            push @queue, ('0') x $rem;
            $rem = 0;
         }
      }
      return shift(@queue);
   };
}

lib/QRCode/Encoder/Matrix.pm  view on Meta::CPAN

   my $penalty = 0;
   my $penalty2 = 0;
   for my $i (0 .. ($side_size - 1)) {
      for my $seq (__row($matrix, $i), __col($matrix, $i)) {

         # adjacences
         my @contributions =
            map  { $_ -  2 }
            grep { $_ >= 5 }
            map  { length  }
            split m{(0+)}mxs, $seq;
         $penalty += sum(@contributions) if @contributions;

         # 000011311 | 113110000
         my @matches = $seq =~ m{
            (
                 (?: (?<=0000) 1011101           )  # look behind...
               | (?:           1011101 (?=0000)  )  # or look ahead
            )
         }gmxs;
         $penalty2 += 40 * scalar(@matches);

t/01-hello.t  view on Meta::CPAN

.    * *** * **** *** *  *
.    *     *    ***   * **
.    ******* ** * ***    *
. 
. 
. 
. 
END
   my $w = 4 + 21 + 4;
   my @retval = map {
      my @row = split m{}mxs, $_;
      shift(@row);
      push @row, ' ' while @row < $w;
      \@row;
   } split m{\n}mxs, $string;
   return \@retval;
}

sub expected_matrix {
   return [
      [
         48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
         48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 ],
      [
         48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,



( run in 0.874 second using v1.01-cache-2.11-cpan-71847e10f99 )