Permalink
Browse files

perltidy

  • Loading branch information...
abh committed Aug 24, 2010
1 parent 79b236a commit c81aa5e27e364e080a3e2aee9a60e4d406e3c97d
Showing with 65 additions and 35 deletions.
  1. +36 −0 .perltidyrc
  2. +29 −35 pgeodns
View
@@ -0,0 +1,36 @@
+# 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 PBP
+
+--maximum-line-length=100 # be slightly more 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 #
+-ci=2 # Continuation indent is 2 cols
+
+# we use version control, so just rewrite the file
+-b
+
+# for the up-tight folk :)
+-pt=2 # High parenthesis tightness
+-bt=2 # High brace tightness
+-sbt=2 # High square bracket tightness
+
View
64 pgeodns
@@ -12,30 +12,24 @@ use Getopt::Long;
use Socket;
my %opts = (verbose => 0);
-GetOptions (\%opts,
- 'interface=s@',
- 'user=s',
- 'verbose!',
- 'config=s',
- 'configtest!',
- 'development!',
- 'port=i',
- ) or die "invalid options";
+GetOptions(\%opts, 'interface=s@', 'user=s', 'verbose!', 'config=s', 'configtest!', 'development!',
+ 'port=i',)
+ or die "invalid options";
my $config_file = $opts{config} || 'pgeodns.conf';
-my $port = $opts{port} || 53;
+my $port = $opts{port} || 53;
-exit !GeoDNS::load_config({},$config_file)
+exit !GeoDNS::load_config({}, $config_file)
if $opts{configtest};
die "--interface [ip|hostname] required\n" unless $opts{interface};
-die "--user [user|uid] required\n" if $> ==0 and !$opts{user};
+die "--user [user|uid] required\n" if $> == 0 and !$opts{user};
-$opts{interface} = [ $opts{interface} ] unless ref $opts{interface};
-$opts{interface} = [ map { split /\s*,\s*/ } @{$opts{interface}} ];
+$opts{interface} = [$opts{interface}] unless ref $opts{interface};
+$opts{interface} = [map { split /\s*,\s*/ } @{$opts{interface}}];
-for my $i ( 0 .. scalar @{$opts{interface}} - 1) {
+for my $i (0 .. scalar @{$opts{interface}} - 1) {
my $localaddr = $opts{interface}->[$i];
if ($localaddr =~ /[^\d\.]/) {
my $addr = inet_ntoa((gethostbyname($localaddr))[4]);
@@ -44,47 +38,47 @@ for my $i ( 0 .. scalar @{$opts{interface}} - 1) {
}
}
-my $g = GeoDNS->new(server_id => $opts{interface}->[0],
- debug => 1,
- config_file => $opts{config},
- development => ($opts{development} ? 1 : 0),
- );
+my $g = GeoDNS->new(
+ server_id => $opts{interface}->[0],
+ debug => 1,
+ config_file => $opts{config},
+ development => ($opts{development} ? 1 : 0),
+);
printf "\nStarting GeoDNS %s\n", $g->version_full;
-my $ns = Net::DNS::Nameserver->new
- (
- LocalPort => $port,
- LocalAddr => $opts{interface},
- ReplyHandler => sub {
- my @reply = $g->reply_handler(@_);
- #warn Data::Dumper->Dump([\@reply], [qw(reply)]);
- @reply
- },
- Verbose => $opts{verbose},
- );
+my $ns = Net::DNS::Nameserver->new(
+ LocalPort => $port,
+ LocalAddr => $opts{interface},
+ ReplyHandler => sub {
+ my @reply = $g->reply_handler(@_);
+
+ #warn Data::Dumper->Dump([\@reply], [qw(reply)]);
+ @reply;
+ },
+ Verbose => $opts{verbose},
+);
# print error?
die "couldn't create nameserver object\n" unless $ns;
if (my $uid = $opts{user}) {
$uid = getpwnam($uid) or die "could not lookup uid"
- if $uid =~ m/\D/;
+ if $uid =~ m/\D/;
setuid($uid) or die "could not setuid: $!";
}
$g->load_config($config_file);
if ($ns) {
- $ns->main_loop;
+ $ns->main_loop;
}
else {
- die "couldn't create nameserver object\n";
+ die "couldn't create nameserver object\n";
}
-
__END__
=pod

0 comments on commit c81aa5e

Please sign in to comment.