Skip to content

Commit

Permalink
modernized ".perltidyrc"
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 9, 2012
1 parent 4fabfea commit 8294c06
Show file tree
Hide file tree
Showing 86 changed files with 1,185 additions and 1,316 deletions.
1 change: 1 addition & 0 deletions .perltidyrc
Expand Up @@ -10,3 +10,4 @@
-bt=2 # High brace tightness
-sbt=2 # High square bracket tightness
-isbc # Don't indent comments without leading space
-sac # Stack all containers
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@

3.66 2012-12-10
- Improved documentation.
- Modernized ".perltidyrc".

3.65 2012-12-09
- Added upgrade method to Mojo::UserAgent::Transactor.
Expand Down
9 changes: 5 additions & 4 deletions README.pod
Expand Up @@ -116,10 +116,11 @@ Web development for humans, making hard things possible and everything fun.
# WebSocket echo service
websocket '/echo' => sub {
my $self = shift;
$self->on(message => sub {
my ($self, $msg) = @_;
$self->send("echo: $msg");
});
$self->on(
message => sub {
my ($self, $msg) = @_;
$self->send("echo: $msg");
});
};

app->start;
Expand Down
18 changes: 6 additions & 12 deletions examples/connect-proxy.pl
Expand Up @@ -48,35 +48,29 @@
read => sub {
my ($stream, $chunk) = @_;
Mojo::IOLoop->stream($client)->write($chunk);
}
);
});

# Server closed connection
$stream->on(
close => sub {
Mojo::IOLoop->remove($client);
delete $buffer{$client};
}
);
}
);
});
});
}
}

# Invalid request from client
else { Mojo::IOLoop->remove($client) }
}
);
});

# Client closed connection
$stream->on(
close => sub {
my $buffer = delete $buffer{$client};
Mojo::IOLoop->remove($buffer->{connection}) if $buffer->{connection};
}
);
}
) or die "Couldn't create listen socket!\n";
});
}) or die "Couldn't create listen socket!\n";

print <<'EOF';
Starting connect proxy on port 3000.
Expand Down
6 changes: 2 additions & 4 deletions examples/microhttpd.pl
Expand Up @@ -28,11 +28,9 @@
$stream->write("HTTP/1.1 200 OK\x0d\x0a"
. "Connection: keep-alive\x0d\x0a\x0d\x0a");
}
}
);
});
$stream->on(close => sub { delete $buffer{$id} });
}
) or die "Couldn't create listen socket!\n";
}) or die "Couldn't create listen socket!\n";

print <<'EOF';
Starting server on port 3000.
Expand Down
18 changes: 10 additions & 8 deletions lib/Mojo/Asset/Memory.pm
Expand Up @@ -77,17 +77,19 @@ L<Mojo::Asset::Memory> can emit the following events.
=head2 C<upgrade>
$mem->on(upgrade => sub {
my ($mem, $file) = @_;
...
});
$mem->on(
upgrade => sub {
my ($mem, $file) = @_;
...
});
Emitted when asset gets upgraded to a L<Mojo::Asset::File> object.
$mem->on(upgrade => sub {
my ($mem, $file) = @_;
$file->tmpdir('/tmp');
});
$mem->on(
upgrade => sub {
my ($mem, $file) = @_;
$file->tmpdir('/tmp');
});
=head1 ATTRIBUTES
Expand Down
18 changes: 10 additions & 8 deletions lib/Mojo/Collection.pm
Expand Up @@ -91,10 +91,11 @@ Mojo::Collection - Collection
use Mojo::Collection;
my $collection = Mojo::Collection->new(qw(just works));
unshift @$collection, 'it';
$collection->map(sub { ucfirst })->each(sub {
my ($word, $count) = @_;
say "$count: $word";
});
$collection->map(sub { ucfirst })->each(
sub {
my ($word, $count) = @_;
say "$count: $word";
});
# Use the alternative constructor
use Mojo::Collection 'c';
Expand Down Expand Up @@ -132,10 +133,11 @@ Construct a new array-based L<Mojo::Collection> object.
Evaluate callback for each element in collection.
$collection->each(sub {
my ($e, $count) = @_;
say "$count: $e";
});
$collection->each(
sub {
my ($e, $count) = @_;
say "$count: $e";
});
=head2 C<first>
Expand Down
54 changes: 30 additions & 24 deletions lib/Mojo/Content.pm
Expand Up @@ -366,46 +366,52 @@ L<Mojo::Content> can emit the following events.
=head2 C<body>
$content->on(body => sub {
my $content = shift;
...
});
$content->on(
body => sub {
my $content = shift;
...
});
Emitted once all headers have been parsed and the body starts.
$content->on(body => sub {
my $content = shift;
$content->auto_upgrade(0) if $content->headers->header('X-No-MultiPart');
});
$content->on(
body => sub {
my $content = shift;
$content->auto_upgrade(0) if $content->headers->header('X-No-MultiPart');
});
=head2 C<drain>
$content->on(drain => sub {
my ($content, $offset) = @_;
...
});
$content->on(
drain => sub {
my ($content, $offset) = @_;
...
});
Emitted once all data has been written.
$content->on(drain => sub {
my $content = shift;
$content->write_chunk(time);
});
$content->on(
drain => sub {
my $content = shift;
$content->write_chunk(time);
});
=head2 C<read>
$content->on(read => sub {
my ($content, $chunk) = @_;
...
});
$content->on(
read => sub {
my ($content, $chunk) = @_;
...
});
Emitted when a new chunk of content arrives.
$content->unsubscribe('read');
$content->on(read => sub {
my ($content, $chunk) = @_;
say "Streaming: $chunk";
});
$content->on(
read => sub {
my ($content, $chunk) = @_;
say "Streaming: $chunk";
});
=head1 ATTRIBUTES
Expand Down
20 changes: 11 additions & 9 deletions lib/Mojo/Content/MultiPart.pm
Expand Up @@ -226,18 +226,20 @@ emit the following new ones.
=head2 C<part>
$multi->on(part => sub {
my ($multi, $single) = @_;
...
});
$multi->on(
part => sub {
my ($multi, $single) = @_;
...
});
Emitted when a new L<Mojo::Content::Single> part starts.
$multi->on(part => sub {
my ($multi, $single) = @_;
return unless $single->headers->content_disposition =~ /name="([^"]+)"/;
say "Field: $1";
});
$multi->on(
part => sub {
my ($multi, $single) = @_;
return unless $single->headers->content_disposition =~ /name="([^"]+)"/;
say "Field: $1";
});
=head1 ATTRIBUTES
Expand Down
20 changes: 11 additions & 9 deletions lib/Mojo/Content/Single.pm
Expand Up @@ -85,18 +85,20 @@ emit the following new ones.
=head2 C<upgrade>
$single->on(upgrade => sub {
my ($single, $multi) = @_;
...
});
$single->on(
upgrade => sub {
my ($single, $multi) = @_;
...
});
Emitted when content gets upgraded to a L<Mojo::Content::MultiPart> object.
$single->on(upgrade => sub {
my ($single, $multi) = @_;
return unless $multi->headers->content_type =~ /multipart\/([^;]+)/i;
say "Multipart: $1";
});
$single->on(
upgrade => sub {
my ($single, $multi) = @_;
return unless $multi->headers->content_type =~ /multipart\/([^;]+)/i;
say "Multipart: $1";
});
=head1 ATTRIBUTES
Expand Down
27 changes: 15 additions & 12 deletions lib/Mojo/EventEmitter.pm
Expand Up @@ -103,10 +103,11 @@ Mojo::EventEmitter - Event emitter base class
# Subscribe to events
my $tiger = Cat->new;
$tiger->on(roar => sub {
my ($tiger, $times) = @_;
say 'RAWR!' for 1 .. $times;
});
$tiger->on(
roar => sub {
my ($tiger, $times) = @_;
say 'RAWR!' for 1 .. $times;
});
$tiger->poke;
=head1 DESCRIPTION
Expand Down Expand Up @@ -144,21 +145,23 @@ Check if event has subscribers.
Subscribe to event.
$e->on(foo => sub {
my ($e, @args) = @_;
...
});
$e->on(
foo => sub {
my ($e, @args) = @_;
...
});
=head2 C<once>
my $cb = $e->once(foo => sub {...});
Subscribe to event and unsubscribe again after it has been emitted once.
$e->once(foo => sub {
my ($e, @args) = @_;
...
});
$e->once(
foo => sub {
my ($e, @args) = @_;
...
});
=head2 C<subscribers>
Expand Down

0 comments on commit 8294c06

Please sign in to comment.