AnyEvent

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


7.13 Sat Sep 17 04:31:49 CEST 2016
	- Only call tlsext_host_name for non-empty common names (reported
          by Maxime Soulé).
        - log a (single) notice message if SNI is not supported.
        - upgrade to UTS-46:9.0.0 draft and switch to non-transitional
          behaviour, beating thunderbird, ie, edge, chrome and safari to it :)
          (see also https://bugzilla.mozilla.org/show_bug.cgi?id=1218179)
        - turns out the UTS-46 IDNA testcase failures were indeed bugs in the
          testcases and the specification and not in the code - the post-9.0.0
          unicode files have all known problems fixed, so finally the AnyEvent
          IDNA implementation can pass the full IDNA testsuite - without needing
          a single fix :)
        - guarantee (and document) that condvar callbacks will be removed
          on invocation - important to avoid circular references.

7.12 Wed Jan 27 19:12:26 CET 2016
	- use common name as hostname for tls connects, if Net::SSLeay
          supports SNI.
        - fix documentation of tls_autostart read type in AnyEvent::Handle,
          analyzed by Felix Ostmann.

Changes  view on Meta::CPAN

        - load /etc/hosts only when DNS has no answer.
        - stat /etc/hosts on every access and reload it if it changed.
        - load /etc/hosts via AnyEvent::IO - potentially asynchronous.
        - fix a buggy croak in the dh parameter reading in AnyEvent::TLS.
        - AnyEvent::Log log_to_file and log_to_path now use AnyEvent::IO. As
          a side effect, they now use true appending as opposed to libc
          appending, and the file might not have been opened when the function
          returns.
        - the default logging level was not properly documented in a variety of
          places, this has hopefully been rectified.
	- updated uts46data.pl for unicode 6.1.0.
        - made log messages generated by AnyEvent submodules not
          include the package name anymore, as it will be logged
          by default already.
        - upgrade to the trick used by common-sense 3.5 to work
          around extra warning torture/breakage under perl 5.15.x.
        - log messages by anyevent are now ucfirst, are usually full
          sentences and do no longer include the package name.
        - the storable read type would sometimes throw an exception instead
          of causing EBADMSG (analyzed by Maxime Soulé).
        - work around a bug in openssl 1.0.1 which enforces a minimum rsa

Changes  view on Meta::CPAN

          by lucky accident on win32.
        - smaller and faster AnyEvent::Util::fh_nonblocking.
        - when the (required!) Time::HiRes module is missing, AnyEvent
          did not fall back to built-in time properly.
        - do not load Fcntl at runtime, saving memory and loading time.
        - precompile a number of constants and use them instead of runtime
          detection and eval.
        - free detection code after detection and similar memory optimisations.
        - Perl backend timer interval best effort drift has been improved
          (same algorithm as EV).
        - update unicode idna mapping table.

5.24  Tue Jan  5 11:39:43 CET 2010
	- cygwin never reports errors from failed connects. 1.5 just gives
          you continous readyness and EAGAIN, 1.7 is even more broken and
          just hangs. work around both issues in a cygwin-specific hack.
	- improve idle watcher documentation slightly.

5.23  Sun Dec 20 23:48:00 CET 2009
	- support IDNs in resolve_sockaddr, and therefore in tcp_connect.
        - implement punycode_encode/decode, idn_nameprep,
          idn_to_ascii and idn_to_unicode operations in AnyEvent::Util.
	- provide $AE::VERSION.
        - removed traces of "no strict 'refs'".

5.22  Sat Dec  5 03:51:13 CET 2009
	- downgrade-or-fail in AnyEvent::Handle::push_write, to
          diagnose encoding failures earlier and more succinctly.
          (this works around bugs in perl, throwing away encoding info
          when passing scalar data to extensions).
        - add more examples to AnyEvent::Socket manpage.
        - upgrade internal warning set to the same as common::sense 2.03.

README  view on Meta::CPAN

NAME
    AnyEvent - the DBI of event loop programming

    EV, Event, Glib, Tk, UV, Perl, Event::Lib, Irssi, rxvt-unicode,
    IO::Async, Qt, FLTK and POE are various supported event
    loops/environments.

SYNOPSIS
       use AnyEvent;

       # if you prefer function calls, look at the AE manpage for
       # an alternative API.

       # file handle or descriptor readable

README  view on Meta::CPAN

        POE backend, so it can be supported through POE.

        AnyEvent knows about both Prima and Wx, however, and will try to
        load POE when detecting them, in the hope that POE will pick them
        up, in which case everything will be automatic.

    Known event loops outside the AnyEvent distribution
        The following event loops or programs support AnyEvent by providing
        their own AnyEvent backend. They will be picked up automatically.

           urxvt::anyevent           available to rxvt-unicode extensions

GLOBAL VARIABLES AND FUNCTIONS
    These are not normally required to use AnyEvent, but can be useful to
    write AnyEvent extension modules.

    $AnyEvent::MODEL
        Contains "undef" until the first watcher is being created, before
        the backend has been autodetected.

        Afterwards it contains the event model that is being used, which is
        the name of the Perl class implementing the model. This class is
        usually one of the "AnyEvent::Impl::xxx" modules, but can be any
        other class in the case AnyEvent has been extended at runtime (e.g.
        in *rxvt-unicode* it will be "urxvt::anyevent").

    AnyEvent::detect
        Returns $AnyEvent::MODEL, forcing autodetection of the event model
        if necessary. You should only call this function right before you
        would have created an AnyEvent watcher anyway, that is, as late as
        possible at runtime, and not e.g. during initialisation of your
        module.

        The effect of calling this function is as if a watcher had been
        created (specifically, actions that happen "when the first watcher

README  view on Meta::CPAN

    "urxvt::anyevent" module.

    The class should provide implementations for all watcher types. See
    AnyEvent::Impl::EV (source code), AnyEvent::Impl::Glib (Source code) and
    so on for actual examples. Use "perldoc -m AnyEvent::Impl::Glib" to see
    the sources.

    If you don't provide "signal" and "child" watchers than AnyEvent will
    provide suitable (hopefully) replacements.

    The above example isn't fictitious, the *rxvt-unicode* (a.k.a. urxvt)
    terminal emulator uses the above line as-is. An interface isn't included
    in AnyEvent because it doesn't make sense outside the embedded
    interpreter inside *rxvt-unicode*, and it is updated and maintained as
    part of the *rxvt-unicode* distribution.

    *rxvt-unicode* also cheats a bit by not providing blocking access to
    condition variables: code blocking while waiting for a condition will
    "die". This still works with most modules/usages, and blocking calls
    must not be done in an interactive application, so it makes sense.

EXAMPLE PROGRAM
    The following program uses an I/O watcher to read data from STDIN, a
    timer to display a message once per second, and a condition variable to
    quit the program when the user enters quit:

       use AnyEvent;

lib/AnyEvent.pm  view on Meta::CPAN

=head1 NAME

AnyEvent - the DBI of event loop programming

EV, Event, Glib, Tk, UV, Perl, Event::Lib, Irssi, rxvt-unicode, IO::Async,
Qt, FLTK and POE are various supported event loops/environments.

=head1 SYNOPSIS

   use AnyEvent;

   # if you prefer function calls, look at the AE manpage for
   # an alternative API.

   # file handle or descriptor readable

lib/AnyEvent.pm  view on Meta::CPAN


AnyEvent knows about both L<Prima> and L<Wx>, however, and will try to
load L<POE> when detecting them, in the hope that POE will pick them up,
in which case everything will be automatic.

=item Known event loops outside the AnyEvent distribution

The following event loops or programs support AnyEvent by providing their
own AnyEvent backend. They will be picked up automatically.

   urxvt::anyevent           available to rxvt-unicode extensions

=back

=head1 GLOBAL VARIABLES AND FUNCTIONS

These are not normally required to use AnyEvent, but can be useful to
write AnyEvent extension modules.

=over 4

=item $AnyEvent::MODEL

Contains C<undef> until the first watcher is being created, before the
backend has been autodetected.

Afterwards it contains the event model that is being used, which is the
name of the Perl class implementing the model. This class is usually one
of the C<AnyEvent::Impl::xxx> modules, but can be any other class in the
case AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode> it
will be C<urxvt::anyevent>).

=item AnyEvent::detect

Returns C<$AnyEvent::MODEL>, forcing autodetection of the event model
if necessary. You should only call this function right before you would
have created an AnyEvent watcher anyway, that is, as late as possible at
runtime, and not e.g. during initialisation of your module.

The effect of calling this function is as if a watcher had been created

lib/AnyEvent.pm  view on Meta::CPAN

C<urxvt::anyevent> module.

The class should provide implementations for all watcher types. See
L<AnyEvent::Impl::EV> (source code), L<AnyEvent::Impl::Glib> (Source code)
and so on for actual examples. Use C<perldoc -m AnyEvent::Impl::Glib> to
see the sources.

If you don't provide C<signal> and C<child> watchers than AnyEvent will
provide suitable (hopefully) replacements.

The above example isn't fictitious, the I<rxvt-unicode> (a.k.a. urxvt)
terminal emulator uses the above line as-is. An interface isn't included
in AnyEvent because it doesn't make sense outside the embedded interpreter
inside I<rxvt-unicode>, and it is updated and maintained as part of the
I<rxvt-unicode> distribution.

I<rxvt-unicode> also cheats a bit by not providing blocking access to
condition variables: code blocking while waiting for a condition will
C<die>. This still works with most modules/usages, and blocking calls must
not be done in an interactive application, so it makes sense.

=head1 EXAMPLE PROGRAM

The following program uses an I/O watcher to read data from STDIN, a timer
to display a message once per second, and a condition variable to quit the
program when the user enters quit:

lib/AnyEvent/Intro.pod  view on Meta::CPAN

event loops, just like DBI is an abstraction of many different database
APIs. Its main purpose is to move the choice of the underlying framework
(the event loop) from the module author to the program author using the
module.

That means you can write code that uses events to control what it
does, without forcing other code in the same program to use the same
underlying framework as you do - i.e. you can create a Perl module
that is event-based using AnyEvent, and users of that module can still
choose between using L<Gtk2>, L<Tk>, L<Event> (or run inside Irssi or
rxvt-unicode) or any other supported event loop. AnyEvent even comes with
its own pure-perl event loop implementation, so your code works regardless
of other modules that might or might not be installed. The latter is
important, as AnyEvent does not have any hard dependencies to other
modules, which makes it easy to install, for example, when you lack a C
compiler. No matter what environment, AnyEvent will just cope with it.

A typical limitation of existing Perl modules such as L<Net::IRC> is that
they come with their own event loop: In L<Net::IRC>, a program which uses
it needs to start the event loop of L<Net::IRC>. That means that one
cannot integrate this module into a L<Gtk2> GUI for instance, as that

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

use Socket ();

use AnyEvent (); BEGIN { AnyEvent::common_sense }

use base 'Exporter';

our @EXPORT = qw(fh_nonblocking guard fork_call portable_pipe portable_socketpair run_cmd);
our @EXPORT_OK = qw(
   AF_INET6 WSAEWOULDBLOCK WSAEINPROGRESS WSAEINVAL
   close_all_fds_except
   punycode_encode punycode_decode idn_nameprep idn_to_ascii idn_to_unicode
);

our $VERSION = $AnyEvent::VERSION;

BEGIN {
   # provide us with AF_INET6, but only if allowed
   if (
      $AnyEvent::PROTOCOL{ipv6}
      && _AF_INET6
      && socket my $ipv6_socket, _AF_INET6, Socket::SOCK_DGRAM(), 0 # check if they can be created

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

=item AnyEvent::Util::punycode_encode $string

Punycode-encodes the given C<$string> and returns its punycode form. Note
that uppercase letters are I<not> casefolded - you have to do that
yourself.

Croaks when it cannot encode the string.

=item AnyEvent::Util::punycode_decode $string

Tries to punycode-decode the given C<$string> and return its unicode
form. Again, uppercase letters are not casefoled, you have to do that
yourself.

Croaks when it cannot decode the string.

=cut

sub punycode_encode($) {
   require "AnyEvent/Util/idna.pl";
   goto &punycode_encode;

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

         or $_[1] && 0 <= index $uts46_imap, pack "C0U*", 0, ord, 1 # deviation == \x00$chr\x01
         or Carp::croak "$_[0]: disallowed characters during idn_nameprep"
         for split //;
   }

   $_
}

=item $domainname = AnyEvent::Util::idn_to_ascii $idn

Converts the given unicode string (C<$idn>, international domain name,
e.g. 日本語。JP) to a pure-ASCII domain name (this is usually
called the "IDN ToAscii" transform). This transformation is idempotent,
which means you can call it just in case and it will do the right thing.

Unlike some other "ToAscii" implementations, this one works on full domain
names and should never fail - if it cannot convert the name, then it will
return it unchanged.

This function is an amalgam of IDNA2003, UTS#46 and IDNA2008 - it tries to
be reasonably compatible to other implementations, reasonably secure, as

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


      1
   } or return $_[0];

   shift @output
      while !length $output[0] && @output > 1;

   join ".", @output
}

=item $idn = AnyEvent::Util::idn_to_unicode $idn

Converts the given unicode string (C<$idn>, international domain name,
e.g. 日本語。JP, www.deliantra.net, www.xn--l-0ga.de) to
unicode form (this is usually called the "IDN ToUnicode" transform). This
transformation is idempotent, which means you can call it just in case and
it will do the right thing.

Unlike some other "ToUnicode" implementations, this one works on full
domain names and should never fail - if it cannot convert the name, then
it will return it unchanged.

This function is an amalgam of IDNA2003, UTS#46 and IDNA2008 - it tries to
be reasonably compatible to other implementations, reasonably secure, as
much as IDNs can be secure, and reasonably efficient when confronted with
IDNs that are already valid DNS names.

At the moment, this function simply calls C<idn_nameprep $idn, 1>,
returning its argument when that function fails.

=cut

sub idn_to_unicode($) {
   my $res = eval { idn_nameprep $_[0], 1 };
   defined $res ? $res : $_[0]
}

=back

=head1 AUTHOR

 Marc Lehmann <schmorp@schmorp.de>
 http://anyevent.schmorp.de

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]/;

   /^
    ([0-9A-F]{4,}) (?: \.\.([0-9A-F]{4,}) )?

util/tst_uts46data  view on Meta::CPAN


# 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";

util/tst_uts46data  view on Meta::CPAN

   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;

   $tou = $source unless length $tou;
   $toa = $tou    unless length $toa;

   my $xtou =    AnyEvent::Util::idn_to_unicode $source;
   my $xtoa = lc AnyEvent::Util::idn_to_ascii   $source;

   $xtoa = "[error]" unless defined $xtoa;
   $xtou = "[error]" unless defined $xtou;

   if ($tou ne $xtou) {
      warn "$. TOU ERROR $type ($source expect $tou got $xtou) ($@)\n"
         unless $tou =~ /^\[/;
   }



( run in 0.442 second using v1.01-cache-2.11-cpan-88abd93f124 )