Skip to content

Commit

Permalink
merged v4.90 of upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadam committed May 30, 2014
1 parent 61dd5b9 commit b20b5be
Show file tree
Hide file tree
Showing 96 changed files with 1,752 additions and 1,192 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v4.90 2014-05-30 00:00:00
- merged v4.84 of upstream
v4.84 2014-02-24 00:00:00
- merged v4.84 of upstream
v4.67 2014-01-14 00:00:00
Expand Down
7 changes: 3 additions & 4 deletions lib/Mojo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ Mojo - Duct tape for the HTML5 web!
=head1 DESCRIPTION
Mojo provides a flexible runtime environment for Perl real-time web
frameworks. It provides all the basic tools and helpers needed to write
simple web applications and higher level web frameworks, such as
L<Mojolicious>.
A flexible runtime environment for Perl real-time web frameworks, with all the
basic tools and helpers needed to write simple web applications and higher
level web frameworks, such as L<Mojolicious>.
See L<Mojolicious::Guides> for more!
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Asset/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ necessary.
$file = $file->tmpdir('/tmp');
Temporary directory used to generate L</"path">, defaults to the value of the
MOJO_TMPDIR environment variable or auto detection.
C<MOJO_TMPDIR> environment variable or auto detection.
=head1 METHODS
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Asset/Memory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ automatically upgrade to a L<Mojo::Asset::File> object.
Maximum size in bytes of data to keep in memory before automatically upgrading
to a L<Mojo::Asset::File> object, defaults to the value of the
MOJO_MAX_MEMORY_SIZE environment variable or C<262144>.
C<MOJO_MAX_MEMORY_SIZE> environment variable or C<262144>.
=head1 METHODS
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ sub import {
}

sub attr {
my ($class, $attrs, $default) = @_;
return unless ($class = ref $class || $class) && $attrs;
my ($self, $attrs, $default) = @_;
return unless (my $class = ref $self || $self) && $attrs;

Carp::croak 'Default has to be a code reference or constant value'
if ref $default && ref $default ne 'CODE';
Expand Down Expand Up @@ -227,7 +227,7 @@ Backported from perl-5.10.1
=head1 DEBUGGING
You can set the MOJO_BASE_DEBUG environment variable to get some advanced
You can set the C<MOJO_BASE_DEBUG> environment variable to get some advanced
diagnostics information printed to C<STDERR>.
MOJO_BASE_DEBUG=1
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojo/ByteStream.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ sub new {
my ($self, $handle) = @_;
$handle ||= \*STDOUT;
print $handle $$self. "\n";
return $self;
}
}

Expand Down Expand Up @@ -221,8 +222,8 @@ Quote bytestream with L<Mojo::Util/"quote">.
=head2 say
$stream->say;
$stream->say(*STDERR);
$stream = $stream->say;
$stream = $stream->say(*STDERR);
Print bytestream to handle and append a newline, defaults to C<STDOUT>.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Collection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ sub _flatten {
map { _ref($_) ? _flatten(@$_) : $_ } @_;
}

sub _ref { ref $_[0] eq 'ARRAY' || (blessed $_[0] && $_[0]->isa(__PACKAGE__)) }
sub _ref { ref $_[0] eq 'ARRAY' || blessed $_[0] && $_[0]->isa(__PACKAGE__) }

1;

Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Content.pm
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ Content headers, defaults to a L<Mojo::Headers> object.
$content = $content->max_buffer_size(1024);
Maximum size in bytes of buffer for content parser, defaults to the value of
the MOJO_MAX_BUFFER_SIZE environment variable or C<262144>.
the C<MOJO_MAX_BUFFER_SIZE> environment variable or C<262144>.
=head2 max_leftover_size
my $size = $content->max_leftover_size;
$content = $content->max_leftover_size(1024);
Maximum size in bytes of buffer for pipelined HTTP requests, defaults to the
value of the MOJO_MAX_LEFTOVER_SIZE environment variable or C<262144>.
value of the C<MOJO_MAX_LEFTOVER_SIZE> environment variable or C<262144>.
=head2 relaxed
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/DOM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ Render this node and its content to HTML/XML.
=head2 tree
my $tree = $dom->tree;
$dom = $dom->tree(['root', ['text', 'foo']]);
$dom = $dom->tree(['root']);
Document Object Model. Note that this structure should only be used very
carefully since it is very dynamic.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/DOM/CSS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ L<Mojo::DOM::CSS> implements the following attributes.
=head2 tree
my $tree = $css->tree;
$css = $css->tree(['root', ['text', 'foo']]);
$css = $css->tree(['root']);
Document Object Model. Note that this structure should only be used very
carefully since it is very dynamic.
Expand Down
35 changes: 27 additions & 8 deletions lib/Mojo/DOM/HTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ my $TOKEN_RE = qr/
)??
/xis;

# HTML elements that only contain raw text
my %RAW = map { $_ => 1 } qw(script style);

# HTML elements that only contain raw text and entities
my %RCDATA = map { $_ => 1 } qw(title textarea);

# HTML elements with optional end tags
my %END = (
body => ['head'],
Expand Down Expand Up @@ -85,6 +91,17 @@ my @PHRASING = (
my @OBSOLETE = qw(acronym applet basefont big font strike tt);
my %PHRASING = map { $_ => 1 } @OBSOLETE, @PHRASING;

# HTML elements that don't get their self-closing flag acknowledged
my %BLOCK = map { $_ => 1 } (
qw(a address applet article aside b big blockquote body button caption),
qw(center code col colgroup dd details dialog dir div dl dt em fieldset),
qw(figcaption figure font footer form frameset h1 h2 h3 h4 h5 h6 head),
qw(header hgroup html i iframe li listing main marquee menu nav nobr),
qw(noembed noframes noscript object ol optgroup option p plaintext pre rp),
qw(rt s script section select small strike strong style summary table),
qw(tbody td template textarea tfoot th thead title tr tt u ul xmp)
);

sub parse {
my ($self, $html) = @_;

Expand All @@ -109,26 +126,28 @@ sub parse {
my ($start, $attr) = ($xml ? $1 : lc($1), $2);

# Attributes
my %attrs;
my (%attrs, $closing);
while ($attr =~ /$ATTR_RE/g) {
my ($key, $value) = ($xml ? $1 : lc($1), defined $2 ? $2 : defined $3 ? $3 : $4);

# Empty tag
next if $key eq '/';
++$closing and next if $key eq '/';

$attrs{$key} = defined $value ? html_unescape($value) : $value;
}

# "image" is an alias for "img"
$start = 'img' if !$xml && $start eq 'image';
_start($start, \%attrs, $xml, \$current);

# Element without end tag
# Element without end tag (self-closing)
_end($start, $xml, \$current)
if (!$xml && $EMPTY{$start}) || $attr =~ m!/\s*$!;
if !$xml && $EMPTY{$start} || ($xml || !$BLOCK{$start}) && $closing;

# Relaxed "script" or "style" HTML elements
next if $xml || ($start ne 'script' && $start ne 'style');
# Raw text elements
next if $xml || !$RAW{$start} && !$RCDATA{$start};
next unless $html =~ m!\G(.*?)<\s*/\s*$start\s*>!gcsi;
_node($current, 'raw', $1);
_node($current, 'raw', $RCDATA{$start} ? html_unescape $1 : $1);
_end($start, 0, \$current);
}
}
Expand Down Expand Up @@ -312,7 +331,7 @@ L<Mojo::DOM::HTML> implements the following attributes.
=head2 tree
my $tree = $html->tree;
$html = $html->tree(['root', ['text', 'foo']]);
$html = $html->tree(['root']);
Document Object Model. Note that this structure should only be used very
carefully since it is very dynamic.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/EventEmitter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Unsubscribe from event.
=head1 DEBUGGING
You can set the MOJO_EVENTEMITTER_DEBUG environment variable to get some
You can set the C<MOJO_EVENTEMITTER_DEBUG> environment variable to get some
advanced diagnostics information printed to C<STDERR>.
MOJO_EVENTEMITTER_DEBUG=1
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Headers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ my %NORMALCASE = map { lc($_) => $_ } (
);
for my $header (values %NORMALCASE) {
my $name = lc $header;
$name =~ s/-/_/g;
$name =~ y/-/_/;
monkey_patch __PACKAGE__, $name, sub { scalar shift->header($header => @_) };
}

Expand Down Expand Up @@ -183,7 +183,7 @@ L<Mojo::Headers> implements the following attributes.
$headers = $headers->max_line_size(1024);
Maximum header line size in bytes, defaults to the value of the
MOJO_MAX_LINE_SIZE environment variable or C<10240>.
C<MOJO_MAX_LINE_SIZE> environment variable or C<10240>.
=head1 METHODS
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Home.pm
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ following new ones.
$home = $home->detect;
$home = $home->detect('My::App');
Detect home directory from the value of the MOJO_HOME environment variable or
application class.
Detect home directory from the value of the C<MOJO_HOME> environment variable
or application class.
=head2 lib_dir
Expand Down
46 changes: 34 additions & 12 deletions lib/Mojo/IOLoop.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ sub delay {
sub generate_port { Mojo::IOLoop::Server->generate_port }

sub is_running { _instance(shift)->reactor->is_running }
sub next_tick { _instance(shift)->reactor->next_tick(@_) }
sub one_tick { _instance(shift)->reactor->one_tick }

sub recurring { shift->_timer(recurring => @_) }
Expand Down Expand Up @@ -311,9 +312,9 @@ is loaded.
For better scalability (epoll, kqueue) and to provide IPv6 as well as TLS
support, the optional modules L<EV> (4.0+), L<IO::Socket::IP> (0.20+) and
L<IO::Socket::SSL> (1.75+) will be used automatically if they are installed.
Individual features can also be disabled with the MOJO_NO_IPV6 and MOJO_NO_TLS
environment variables.
L<IO::Socket::SSL> (1.84+) will be used automatically if they are installed.
Individual features can also be disabled with the C<MOJO_NO_IPV6> and
C<MOJO_NO_TLS> environment variables.
See L<Mojolicious::Guides::Cookbook/"REAL-TIME WEB"> for more.
Expand Down Expand Up @@ -493,6 +494,20 @@ Check if event loop is running.
exit unless Mojo::IOLoop->is_running;
=head2 next_tick
my $undef = Mojo::IOLoop->next_tick(sub {...});
my $undef = $loop->next_tick(sub {...});
Invoke callback as soon as possible, but not before returning, always returns
C<undef>.
# Perform operation on next reactor tick
Mojo::IOLoop->next_tick(sub {
my $loop = shift;
...
});
=head2 one_tick
Mojo::IOLoop->one_tick;
Expand All @@ -508,14 +523,18 @@ into the reactor, so you need to be careful.
=head2 recurring
my $id = Mojo::IOLoop->recurring(0.5 => sub {...});
my $id = $loop->recurring(3 => sub {...});
my $id = Mojo::IOLoop->recurring(3 => sub {...});
my $id = $loop->recurring(0 => sub {...});
my $id = $loop->recurring(0.25 => sub {...});
Create a new recurring timer, invoking the callback repeatedly after a given
amount of time in seconds.
# Invoke as soon as possible
Mojo::IOLoop->recurring(0 => sub { say 'Reactor tick.' });
# Perform operation every 5 seconds
Mojo::IOLoop->recurring(5 => sub {
my $loop = shift;
...
});
=head2 remove
Expand Down Expand Up @@ -587,19 +606,22 @@ Get L<Mojo::IOLoop::Stream> object for id or turn object into a connection.
=head2 timer
my $id = Mojo::IOLoop->timer(5 => sub {...});
my $id = $loop->timer(5 => sub {...});
my $id = Mojo::IOLoop->timer(3 => sub {...});
my $id = $loop->timer(0 => sub {...});
my $id = $loop->timer(0.25 => sub {...});
Create a new timer, invoking the callback after a given amount of time in
seconds.
# Invoke as soon as possible
Mojo::IOLoop->timer(0 => sub { say 'Next tick.' });
# Perform operation in 5 seconds
Mojo::IOLoop->timer(5 => sub {
my $loop = shift;
...
});
=head1 DEBUGGING
You can set the MOJO_IOLOOP_DEBUG environment variable to get some advanced
You can set the C<MOJO_IOLOOP_DEBUG> environment variable to get some advanced
diagnostics information printed to C<STDERR>.
MOJO_IOLOOP_DEBUG=1
Expand Down
19 changes: 9 additions & 10 deletions lib/Mojo/IOLoop/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use constant IPV6 => $ENV{MOJO_NO_IPV6}
# TLS support requires IO::Socket::SSL
use constant TLS => $ENV{MOJO_NO_TLS}
? 0
: eval 'use IO::Socket::SSL 1.75 (); 1';
: eval 'use IO::Socket::SSL 1.84 (); 1';
use constant TLS_READ => TLS ? IO::Socket::SSL::SSL_WANT_READ() : 0;
use constant TLS_WRITE => TLS ? IO::Socket::SSL::SSL_WANT_WRITE() : 0;

Expand All @@ -29,14 +29,13 @@ sub connect {
my $self = shift;
my $args = ref $_[0] ? $_[0] : {@_};
weaken $self;
$self->{delay} = $self->reactor->timer(0 => sub { $self->_connect($args) });
$self->reactor->next_tick(sub { $self && $self->_connect($args) });
}

sub _cleanup {
my $self = shift;
return $self unless my $reactor = $self->reactor;
$self->{$_} && $reactor->remove(delete $self->{$_})
for qw(delay timer handle);
$self->{$_} && $reactor->remove(delete $self->{$_}) for qw(timer handle);
return $self;
}

Expand Down Expand Up @@ -98,18 +97,18 @@ sub _try {

return $self->_cleanup->emit_safe(connect => $handle)
if !$args->{tls} || $handle->isa('IO::Socket::SSL');
return $self->emit(error => 'IO::Socket::SSL 1.75 required for TLS support')
return $self->emit(error => 'IO::Socket::SSL 1.84 required for TLS support')
unless TLS;

# Upgrade
weaken $self;
my %options = (
SSL_ca_file => $args->{tls_ca}
&& -T $args->{tls_ca} ? $args->{tls_ca} : undef,
SSL_cert_file => $args->{tls_cert},
SSL_error_trap => sub { $self->_cleanup->emit(error => $_[1]) },
SSL_hostname => $args->{address},
SSL_key_file => $args->{tls_key},
SSL_cert_file => $args->{tls_cert},
SSL_error_trap => sub { $self->_cleanup->emit(error => $_[1]) },
SSL_hostname => IO::Socket::SSL->can_client_sni ? $args->{address} : '',
SSL_key_file => $args->{tls_key},
SSL_startHandshake => 0,
SSL_verify_mode => $args->{tls_ca} ? 0x01 : 0x00,
SSL_verifycn_name => $args->{address},
Expand Down Expand Up @@ -198,7 +197,7 @@ implements the following new ones.
$client->connect(address => '127.0.0.1', port => 3000);
Open a socket connection to a remote host. Note that TLS support depends on
L<IO::Socket::SSL> (1.75+) and IPv6 support on L<IO::Socket::IP> (0.20+).
L<IO::Socket::SSL> (1.84+) and IPv6 support on L<IO::Socket::IP> (0.20+).
These options are currently available:
Expand Down
Loading

0 comments on commit b20b5be

Please sign in to comment.