AnyEvent

 view release on metacpan or  search on metacpan

constants.pl.PL  view on Meta::CPAN

   use warnings qw(FATAL closed threads internal debugging pack malloc portable prototype
                   inplace io pipe unpack glob digit printf
                   layer reserved taint closure semicolon);
   no warnings qw(exec newline unopened);

   BEGIN {
      print "sub AnyEvent::common_sense {\n";
      printf "   local \$^W;\n";
      printf "   \${^WARNING_BITS} ^= \${^WARNING_BITS} ^ \"%s\";\n",
             join "", map "\\x$_", unpack "(H2)*", ${^WARNING_BITS};
      # use strict, use utf8;
      printf "   \$^H |= 0x%x;\n", $^H;
      print "}\n";
   }
}

use Config;

print "# generated for perl $] built for $Config{archname}\n";

# when built as part of perl, these are not available

lib/AnyEvent/Handle.pm  view on Meta::CPAN


      @_ = ($WH{$type} ||= _load_func "$type\::anyevent_write_type"
            or Carp::croak "unsupported/unloadable type '$type' passed to AnyEvent::Handle::push_write")
           ->($self, @_);
   }

   # we downgrade here to avoid hard-to-track-down bugs,
   # and diagnose the problem earlier and better.

   if ($self->{tls}) {
      utf8::downgrade $self->{_tls_wbuf} .= $_[0];
      &_dotls ($self)    if $self->{fh};
   } else {
      utf8::downgrade $self->{wbuf}      .= $_[0];
      $self->_drain_wbuf if $self->{fh};
   }
}

=item $handle->push_write (type => @args)

Instead of formatting your data yourself, you can also let this module
do the job by specifying a type and type-specific arguments. You
can also specify the (fully qualified) name of a package, in which
case AnyEvent tries to load the package and then expects to find the

lib/AnyEvent/Handle.pm  view on Meta::CPAN


   $handle->push_write (cbor => ["method", "arg1", "arg2"]); # whatever
 
An AnyEvent::Handle receiver would simply use the C<cbor> read type:

   $handle->push_read (cbor => sub { my $array = $_[1]; ... });

=cut

sub json_coder() {
   eval { require JSON::XS; JSON::XS->new->utf8 }
      || do { require JSON::PP; JSON::PP->new->utf8 }
}

register_write_type json => sub {
   my ($self, $ref) = @_;

   ($self->{json} ||= json_coder)
      ->encode ($ref)
};

sub cbor_coder() {

lib/AnyEvent/Util.pm  view on Meta::CPAN

      # a char-replacement search string

      # for speed (cough) reasons, we skip-case 0-9a-z, -, ., which
      # really ought to be trivially valid. A-Z is valid, but already lowercased.
      s{
         ([^0-9a-z\-.])
      }{
         my $chr = $1;
         unless (vec $uts46_valid, ord $chr, 1) {
            # not in valid class, search for mapping
            utf8::encode $chr; # the imap table is in utf-8
            (my $rep = index $uts46_imap, "\x00$chr") >= 0
               or Carp::croak "$_[0]: disallowed characters (U+" . (unpack "H*", $chr) . ") during idn_nameprep";

            (substr $uts46_imap, $rep, 128) =~ /\x00 .[\x80-\xbf]* ([^\x00]*) \x00/x
               or die "FATAL: idn_nameprep imap table has unexpected contents";

            $rep = $1;
            $chr = $rep unless $rep =~ s/^\x01// && $_[1]; # replace unless deviation and display
            utf8::decode $chr;
         }
         $chr
      }gex;

      # KC
      $_ = Unicode::Normalize::NFKC ($_);
   }

   # decode punycode components, check for invalid xx-- prefixes
   s{

t/08_idna.t  view on Meta::CPAN

use utf8;

use AnyEvent;
use AnyEvent::Util;

$| = 1; print "1..11\n";

print "ok 1\n";

print "ko-eka" eq (AnyEvent::Util::punycode_encode "\x{f6}ko" ) ? "" : "not ", "ok 2\n";
print "wgv71a" eq (AnyEvent::Util::punycode_encode "\x{65e5}\x{672c}") ? "" : "not ", "ok 3\n";

util/gen_uts46data  view on Meta::CPAN

#!/opt/bin/perl

# creates lib/AnyEvent/Util/uts46.pl - better do not run it!

use common::sense;
use utf8;
no warnings 'utf8';

binmode STDOUT, ":utf8";

open my $fh, "GET http://www.unicode.org/Public/idna/9.0.0/IdnaMappingTable.txt |"
   or die;

my $valid;
my $imap;   # index map \x00 char replacement

while (<$fh>) {
   next unless /^[0-9A-F]/;

util/gen_uts46data  view on Meta::CPAN

         die "default: $R1,$R2,$type,$map;\n";
      }
   }
}

open my $fh, ">lib/AnyEvent/Util/uts46data.pl"
   or die;
binmode $fh, ":perlio";
print $fh "# autogenerated by util/gen_uts46data\n";

utf8::encode $imap;
0 > index $imap, "\x02" # it's not supposed to be anywhere in there
   or die "imap contains \\x02";
print $fh "\$uts46_imap = q\x02$imap\x00\x02;\n";

# try to find a valid quoting character - there usually are many legal combos
for (1..127) { # stay out of utf-8 range
   if (0 >= index $valid, chr) {
      print $fh "\$uts46_valid = q", chr, $valid, chr, ";\n";
      goto valid_ok;
   }

util/tst_uts46data  view on Meta::CPAN

#!/opt/bin/perl

# tests installed AnyEvent against IdnaTest.pl

use common::sense;
use utf8;
no warnings 'utf8';

use Encode;
use AnyEvent::Util;

open my $fh, "GET http://www.unicode.org/Public/idna/9.0.0/IdnaTest.txt |"
   or die;

while (<$fh>) {
   next unless /^[NB]/; # no "T", we implement non-transitional only

   chomp;

   utf8::decode $_
      or die "utf8 decode error: $_\n";

   s/\s*#.*//;

   s/\\u(d[8-b][0-9a-f]{2})\\u(d[c-f][0-9a-f]{2})/Encode::decode "utf-16be", pack "nn", hex $1, hex $2/ige;
   s/\\u([0-9a-fA-F]{4})/chr hex $1/ge;

   my ($type, $source, $tou, $toa, $nv8) = split /[ \t]*;[ \t]*/;

   $toa = lc $toa;



( run in 0.590 second using v1.01-cache-2.11-cpan-49f99fa48dc )