Skip to content

Commit

Permalink
documentation tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 19, 2013
1 parent 2531343 commit f9d40de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
43 changes: 15 additions & 28 deletions lib/Mojo/Util.pm
Expand Up @@ -20,9 +20,6 @@ use constant {
PC_INITIAL_N => 128
};

# Punycode delimiter
my $DELIMITER = chr 0x2D;

# To update HTML5 entities run this command
# perl examples/entities.pl > lib/Mojo/entities.txt
my %ENTITIES;
Expand Down Expand Up @@ -147,20 +144,19 @@ sub monkey_patch {
*{"${class}::$_"} = $patch{$_} for keys %patch;
}

# Direct translation of RFC 3492
sub punycode_decode {
my $input = shift;
use integer;

# Defaults
# Delimiter
my @output;
push @output, split //, $1 if $input =~ s/(.*)\x2d//s;

# Decode
my $n = PC_INITIAL_N;
my $i = 0;
my $bias = PC_INITIAL_BIAS;
my @output;

# Delimiter
if ($input =~ s/(.*)$DELIMITER//s) { push @output, split //, $1 }

# Decode (direct translation of RFC 3492)
while (length $input) {
my $oldi = $i;
my $w = 1;
Expand All @@ -184,47 +180,38 @@ sub punycode_decode {
$n += $i / (@output + 1);
$i = $i % (@output + 1);

# Insert
splice @output, $i, 0, chr($n);
$i++;
splice @output, $i++, 0, chr $n;
}

return join '', @output;
}

# Direct translation of RFC 3492
sub punycode_encode {
use integer;

# Defaults
my $output = shift;
my $len = length $output;
use integer;

# Split input
my @input = map ord, split //, $output;
my $len = length $output;
my @input = map {ord} split //, $output;
my @chars = sort grep { $_ >= PC_INITIAL_N } @input;

# Remove non basic characters
# Handle non basic characters
$output =~ s/[^\x00-\x7f]+//gs;

# Non basic characters in input
my $h = my $b = length $output;
$output .= $DELIMITER if $b > 0;
$output .= "\x2d" if $b > 0;

# Defaults
# Encode
my $n = PC_INITIAL_N;
my $delta = 0;
my $bias = PC_INITIAL_BIAS;

# Encode (direct translation of RFC 3492)
for my $m (@chars) {

# Basic character
next if $m < $n;

# Delta
$delta += ($m - $n) * ($h + 1);

# Walk all code points in order
$delta += ($m - $n) * ($h + 1);
$n = $m;
for (my $i = 0; $i < $len; $i++) {
my $c = $input[$i];
Expand Down
6 changes: 4 additions & 2 deletions lib/Mojolicious.pm
Expand Up @@ -314,8 +314,10 @@ contain more information.
The router, defaults to a L<Mojolicious::Routes> object. You use this in your
startup method to define the url endpoints for your application.
# Add route
$app->routes->get('/:controller/:action')->to('test#welcome');
# Add routes
my $r = $app->routes;
$r->get('/foo/bar')->to('test#foo', title => 'Hello Mojo!');
$r->post('/baz')->to('test#baz');
# Add another namespace to load controllers from
push @{$app->routes->namespaces}, 'MyApp::Controller';
Expand Down

0 comments on commit f9d40de

Please sign in to comment.