Skip to content

Commit

Permalink
modernized .perltidyrc
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 18, 2012
1 parent 99aa643 commit 3b2101d
Show file tree
Hide file tree
Showing 49 changed files with 224 additions and 242 deletions.
40 changes: 9 additions & 31 deletions .perltidyrc
@@ -1,34 +1,12 @@
# Perl Best Practices (plus errata) .perltidyrc file
-l=98 # Max line width is 98 cols
-i=4 # Indent level is 4 cols
-ci=4 # Continuation indent is 4 cols
#-st # Output to STDOUT
-se # Errors to STDERR
-vt=2 # Maximal vertical tightness
-cti=0 # No extra indentation for closing brackets
-pt=1 # Medium parenthesis tightness
-bt=1 # Medium brace tightness
-sbt=1 # Medium square bracket tightness
-bbt=1 # Medium block brace tightness
-nsfs # No space before semicolons
-nolq # Don't outdent long quoted strings
-wbb="% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
# Break before all operators

# Extras/overrides/deviations from Perl Best Practices
--maximum-line-length=78 # Be less generous
--warning-output # Show warnings
--maximum-consecutive-blank-lines=2 # Default is 1
--nohanging-side-comments # Troublesome for commented out code

-isbc # Block comments may only be indented if they have some space characters before the #
-i=2 # Indent level is 2 cols
-ci=2 # Continuation indent is 2 cols

# We use version control, so just rewrite the file
-b

# For the up-tight folk :)
-pbp # Start with Perl Best Practices
-l=78 # 78 character per line
-w # Show all warnings
-mbl=2 # No more than 2 blank lines
-isbc # Don't indent comments without whitespace before the #
-i=2 # Indent level is 2
-ci=2 # Continuation indent is 2
-vt=0 # Less vertical tightness
-b # Just rewrite the file
-pt=2 # High parenthesis tightness
-bt=2 # High brace tightness
-sbt=2 # High square bracket tightness
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.85 2012-04-19
- Modernized .perltidyrc.

2.84 2012-04-19
- Improved documentation.
- Improved tests.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Content.pm
Expand Up @@ -65,8 +65,8 @@ sub get_header_chunk {

unless (defined $self->{header_buffer}) {
my $headers = $self->headers->to_string;
$self->{header_buffer} =
$headers ? "$headers\x0d\x0a\x0d\x0a" : "\x0d\x0a";
$self->{header_buffer}
= $headers ? "$headers\x0d\x0a\x0d\x0a" : "\x0d\x0a";
}

return substr $self->{header_buffer}, $offset, CHUNK_SIZE;
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/DOM.pm
Expand Up @@ -128,8 +128,8 @@ sub find {
my $results = Mojo::DOM::CSS->new(tree => $self->tree)->select($selector);

# Upgrade results
@$results =
map { $self->new->charset($self->charset)->tree($_)->xml($self->xml) }
@$results
= map { $self->new->charset($self->charset)->tree($_)->xml($self->xml) }
@$results;

return Mojo::Collection->new(@$results);
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/DOM/CSS.pm
Expand Up @@ -121,8 +121,8 @@ sub _compile {
# Tokenize
my $pattern = [[]];
while ($css =~ /$TOKEN_RE/g) {
my ($separator, $element, $pc, $attrs, $combinator) =
($1, $2 // '', $3, $6, $11);
my ($separator, $element, $pc, $attrs, $combinator)
= ($1, $2 // '', $3, $6, $11);

# Trash
next unless $separator || $element || $pc || $attrs || $combinator;
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/DOM/HTML.pm
Expand Up @@ -88,8 +88,8 @@ sub parse {
my $tree = ['root'];
my $current = $tree;
while ($html =~ m/\G$TOKEN_RE/gcs) {
my ($text, $pi, $comment, $cdata, $doctype, $tag) =
($1, $2, $3, $4, $5, $6);
my ($text, $pi, $comment, $cdata, $doctype, $tag)
= ($1, $2, $3, $4, $5, $6);

# Text
if (length $text) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -447,8 +447,8 @@ following new ones.
=head2 C<client>
my $id =
Mojo::IOLoop->client(address => '127.0.0.1', port => 3000, sub {...});
my $id
= Mojo::IOLoop->client(address => '127.0.0.1', port => 3000, sub {...});
my $id = $loop->client(address => '127.0.0.1', port => 3000, sub {...});
my $id = $loop->client({address => '127.0.0.1', port => 3000}, sub {...});
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/JSON.pm
Expand Up @@ -257,8 +257,8 @@ sub _encode_object {
my $object = shift;

# Encode pairs
my @pairs =
map { _encode_string($_) . ':' . _encode_values($object->{$_}) }
my @pairs
= map { _encode_string($_) . ':' . _encode_values($object->{$_}) }
keys %$object;

# Stringify
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -348,8 +348,8 @@ sub _spawn {
);

# Clean worker environment
$SIG{INT} = $SIG{TERM} = $SIG{CHLD} = $SIG{USR2} = $SIG{TTIN} = $SIG{TTOU} =
'DEFAULT';
$SIG{INT} = $SIG{TERM} = $SIG{CHLD} = $SIG{USR2} = $SIG{TTIN} = $SIG{TTOU}
= 'DEFAULT';
$SIG{QUIT} = sub { $loop->max_connections(0) };
delete $self->{reader};
delete $self->{poll};
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Template.pm
Expand Up @@ -152,8 +152,8 @@ sub interpret {
# Interpret
return unless my $compiled = $self->compiled;
my $output = eval { $compiled->(@_) };
$output =
Mojo::Exception->new($@, [$self->template], $self->name)->verbose(1)
$output
= Mojo::Exception->new($@, [$self->template], $self->name)->verbose(1)
if $@;

return $output;
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -159,8 +159,8 @@ sub parse_frame {
return unless length $clone > 10;
$hlen = 10;
my $ext = substr $clone, 2, 8;
$len =
$Config{ivsize} > 4
$len
= $Config{ivsize} > 4
? unpack('Q>', $ext)
: unpack('N', substr($ext, 4, 4));
warn "-- Extended 64bit payload ($len)\n" if DEBUG;
Expand Down Expand Up @@ -203,8 +203,8 @@ sub send {

# Binary or raw text
if (ref $frame eq 'HASH') {
$frame =
exists $frame->{text}
$frame
= exists $frame->{text}
? [1, 0, 0, 0, TEXT, $frame->{text}]
: [1, 0, 0, 0, BINARY, $frame->{binary}];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/URL.pm
Expand Up @@ -181,8 +181,8 @@ sub to_abs {
# Inherit path
my $base_path = $base->path;
if (!@{$path->parts}) {
$path =
$abs->path($base_path->clone)->path->trailing_slash(0)->canonicalize;
$path
= $abs->path($base_path->clone)->path->trailing_slash(0)->canonicalize;

# Query
return $abs if length $abs->query->to_string;
Expand Down
17 changes: 7 additions & 10 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -2,6 +2,7 @@ package Mojo::UserAgent;
use Mojo::Base 'Mojo::EventEmitter';

use Carp 'croak';
use List::Util 'first';
use Mojo::CookieJar;
use Mojo::IOLoop;
use Mojo::Server::Daemon;
Expand Down Expand Up @@ -73,18 +74,14 @@ sub detect_proxy {
# Upper case gets priority
$self->http_proxy($ENV{HTTP_PROXY} || $ENV{http_proxy});
$self->https_proxy($ENV{HTTPS_PROXY} || $ENV{https_proxy});
if (my $no = $ENV{NO_PROXY} || $ENV{no_proxy}) {
$self->no_proxy([split /,/, $no]);
}
$self->no_proxy([split /,/, $ENV{NO_PROXY} || $ENV{no_proxy} || '']);

return $self;
}

sub need_proxy {
my ($self, $host) = @_;
return 1 unless my $no = $self->no_proxy;
$host =~ /\Q$_\E$/ and return for @$no;
return 1;
return !first { $host =~ /\Q$_\E$/ } @{$self->no_proxy || []};
}

sub post_form {
Expand Down Expand Up @@ -421,8 +418,8 @@ sub _server {

# Start test server
my $loop = $self->_loop;
my $server = $self->{server} =
Mojo::Server::Daemon->new(ioloop => $loop, silent => 1);
my $server = $self->{server}
= Mojo::Server::Daemon->new(ioloop => $loop, silent => 1);
my $port = $self->{port} = $loop->generate_port;
die "Couldn't find a free TCP port for testing.\n" unless $port;
$self->{scheme} = $scheme ||= 'http';
Expand Down Expand Up @@ -474,8 +471,8 @@ sub _start {
if (my $t = $self->request_timeout) {
weaken $self;
my $loop = $self->_loop;
$self->{connections}{$id}{timeout} =
$loop->timer($t => sub { $self->_error($id => 'Request timeout.') });
$self->{connections}{$id}{timeout}
= $loop->timer($t => sub { $self->_error($id => 'Request timeout.') });
}

return $id;
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Util.pm
Expand Up @@ -341,8 +341,8 @@ sub decode {

# Everything else
else {
$bytes =
($ENCODE{$encoding} ||= find_encoding($encoding))->decode($bytes, 1);
$bytes = ($ENCODE{$encoding} ||= find_encoding($encoding))
->decode($bytes, 1);
}

1;
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojolicious.pm
Expand Up @@ -33,7 +33,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.84';
our $VERSION = '2.85';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down Expand Up @@ -93,8 +93,8 @@ sub new {
$self->hook(
around_dispatch => sub {
my ($next, $c) = @_;
local $SIG{__DIE__} =
sub { ref $_[0] ? CORE::die($_[0]) : Mojo::Exception->throw(@_) };
local $SIG{__DIE__}
= sub { ref $_[0] ? CORE::die($_[0]) : Mojo::Exception->throw(@_) };
$c->render_exception($@) unless eval { $next->(); 1 };
}
);
Expand Down Expand Up @@ -154,8 +154,8 @@ sub handler {
# Build default controller
my $defaults = $self->defaults;
@{$stash}{keys %$defaults} = values %$defaults;
my $c =
$self->controller_class->new(app => $self, stash => $stash, tx => $tx);
my $c
= $self->controller_class->new(app => $self, stash => $stash, tx => $tx);
weaken $c->{app};
weaken $c->{tx};

Expand Down
16 changes: 10 additions & 6 deletions lib/Mojolicious/Command/version.pm
Expand Up @@ -17,16 +17,20 @@ sub run {
my $ev = eval 'use Mojo::Reactor::EV; 1' ? $EV::VERSION : 'not installed';

# IPv6
my $ipv6 =
Mojo::IOLoop::Server::IPV6() ? $IO::Socket::IP::VERSION : 'not installed';
my $ipv6
= Mojo::IOLoop::Server::IPV6()
? $IO::Socket::IP::VERSION
: 'not installed';

# TLS
my $tls =
Mojo::IOLoop::Server::TLS() ? $IO::Socket::SSL::VERSION : 'not installed';
my $tls
= Mojo::IOLoop::Server::TLS()
? $IO::Socket::SSL::VERSION
: 'not installed';

# Bonjour
my $bonjour =
eval 'Mojo::Server::Daemon::BONJOUR()'
my $bonjour
= Mojo::Server::Daemon::BONJOUR()
? $Net::Rendezvous::Publish::VERSION
: 'not installed';

Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -224,8 +224,8 @@ sub render_content {

# Reset with multiple values
if (@_) {
$c->{$name} =
join('', map({ref $_ eq 'CODE' ? $_->() : $_} @_, $content));
$c->{$name}
= join('', map({ref $_ eq 'CODE' ? $_->() : $_} @_, $content));
}

# First come
Expand All @@ -252,8 +252,8 @@ sub render_exception {
return if $stash->{'mojo.exception'};

# Filtered stash snapshot
my %snapshot =
map { $_ => $stash->{$_} }
my %snapshot
= map { $_ => $stash->{$_} }
grep { !/^mojo\./ and defined $stash->{$_} } keys %$stash;

# Render with fallbacks
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -252,8 +252,8 @@ into alien environments like foreign event loops.
get '/' => {text => 'Hello World!'};

# Connect application with web server and start accepting connections
my $daemon =
Mojo::Server::Daemon->new(app => app, listen => ['http://*:8080']);
my $daemon
= Mojo::Server::Daemon->new(app => app, listen => ['http://*:8080']);
$daemon->start;

# Call "one_tick" repeatedly from the alien environment
Expand Down Expand Up @@ -679,8 +679,8 @@ application.
get '/' => {text => 'Hello World!'};

# Connect application with web server and start accepting connections
my $daemon =
Mojo::Server::Daemon->new(app => app, listen => ['http://*:8080']);
my $daemon
= Mojo::Server::Daemon->new(app => app, listen => ['http://*:8080']);
$daemon->start;

# Let AnyEvent take control
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -16,8 +16,8 @@ sub register {
my $template = $conf->{template} || {};

# Custom sandbox
$template->{namespace} //=
'Mojo::Template::SandBox::' . md5_sum(($ENV{MOJO_EXE} || ref $app) . $$);
$template->{namespace} //= 'Mojo::Template::SandBox::'
. md5_sum(($ENV{MOJO_EXE} || ref $app) . $$);

# Auto escape by default to prevent XSS attacks
$template->{auto_escape} //= 1;
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Plugin/I18N.pm
Expand Up @@ -34,8 +34,8 @@ sub register {
);

# Handler
$self->stash->{i18n} =
Mojolicious::Plugin::I18N::_Handler->new(namespace => $namespace);
$self->stash->{i18n}
= Mojolicious::Plugin::I18N::_Handler->new(namespace => $namespace);

# Languages
$self->stash->{i18n}->languages(@languages, $default);
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Plugin/PODRenderer.pm
Expand Up @@ -75,8 +75,8 @@ sub register {
return if $e->all_text =~ /^\s*\$\s+/m;
my $attrs = $e->attrs;
my $class = $attrs->{class};
$attrs->{class} =
defined $class ? "$class prettyprint" : 'prettyprint';
$attrs->{class}
= defined $class ? "$class prettyprint" : 'prettyprint';
}
);

Expand Down
9 changes: 5 additions & 4 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -226,8 +226,9 @@ sub _detect_handler {

# DATA templates
unless ($self->{data}) {
my @templates =
map { sort keys %{Mojo::Command->get_all_data($_)} } @{$self->classes};
my @templates
= map { sort keys %{Mojo::Command->get_all_data($_)} }
@{$self->classes};
s/\.(\w+)$// and $self->{data}{$_} ||= $1 for @templates;
}
return $self->{data}{$file} if exists $self->{data}{$file};
Expand All @@ -249,8 +250,8 @@ sub _render_template {
my ($self, $c, $output, $options) = @_;

# Find handler and render
my $handler =
$options->{handler}
my $handler
= $options->{handler}
|| $self->_detect_handler($options)
|| $self->default_handler;
$options->{handler} = $handler;
Expand Down

0 comments on commit 3b2101d

Please sign in to comment.