Skip to content

Commit

Permalink
many small documentation tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 11, 2011
1 parent 8a14a72 commit bd71622
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 64 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Command.pm
Expand Up @@ -489,7 +489,7 @@ Portably generate an absolute path from a relative UNIX style path.
=head2 C<render_data>
my $data = $command->render_data('foo_bar', @arguments);
my $data = $command->render_data('foo_bar', @args);
Render a template from the C<DATA> section of the command class.
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojo/Content.pm
Expand Up @@ -17,10 +17,9 @@ sub body_contains {
sub body_size { croak 'Method "body_size" not implemented by subclass' }

sub boundary {
return $1
if (shift->headers->content_type || '')
(shift->headers->content_type || '')
=~ m#multipart.*boundary=\"*([a-zA-Z0-9\'\(\)\,\.\:\?\-\_\+/]+)#i;
return;
return $1;
}

# "Operator! Give me the number for 911!"
Expand Down Expand Up @@ -503,7 +502,7 @@ Content size in bytes.
my $boundary = $content->boundary;
Extract multipart boundary from content type header.
Extract multipart boundary from C<Content-Type> header.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<build_body>
Expand All @@ -522,7 +521,7 @@ Render all headers.
my $charset = $content->charset;
Detect content charset.
Extract charset from C<Content-Type> header.
Note that this method is EXPERIMENTAL and might change without warning!
=head2 C<clone>
Expand Down
10 changes: 10 additions & 0 deletions lib/Mojo/EventEmitter.pm
Expand Up @@ -151,18 +151,28 @@ Check if event has subscribers.
Subscribe to event.
$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) = @_;
});
=head2 C<subscribers>
my $subscribers = $e->subscribers('foo');
All subscribers for event.
$e->unsubscribe(foo => $e->subscribers('foo')->[-1]);
=head2 C<unsubscribe>
$e = $e->unsubscribe('foo');
Expand Down
71 changes: 22 additions & 49 deletions lib/Mojo/Exception.pm
Expand Up @@ -16,19 +16,12 @@ has verbose => sub { $ENV{MOJO_EXCEPTION_VERBOSE} || 0 };
# Do they give a Nobel Prize for attempted chemistry?"
sub new {
my $self = shift->SUPER::new();

# Message
return $self unless @_;

# Detect
return $self->_detect(@_);
return @_ ? $self->_detect(@_) : $self;
}

sub throw {
my $self = shift;
my $e = Mojo::Exception->new;
$e->trace(2);
die $e->_detect(@_);
die Mojo::Exception->new->trace(2)->_detect(@_);
}

sub trace {
Expand All @@ -41,11 +34,9 @@ sub trace {
push @frames, [$p, $f, $l];

# Line
if (-r $f) {
next unless my $handle = IO::File->new("< $f");
my @lines = <$handle>;
push @{$frames[-1]}, $lines[$l - 1];
}
next unless -r $f;
next unless my $handle = IO::File->new($f, '<:utf8');
push @{$frames[-1]}, (<$handle>)[$l - 1];
}
$e->frames(\@frames);

Expand All @@ -58,8 +49,7 @@ sub _detect {
# Message
my $message = shift;
return $message if blessed $message && $message->isa('Mojo::Exception');
$self->message($message);
$self->raw_message($message);
$self->message($message)->raw_message($message);

# Trace name and line
my @trace;
Expand All @@ -78,23 +68,16 @@ sub _detect {
my $file = $frame->{file};
my $line = $frame->{line};

# Readable
if (-r $file) {

# Slurp
my $handle = IO::File->new($file, '<:utf8');
my @lines = <$handle>;

# Line
$self->_parse_context($line, [\@lines]);
return $self;
}
# Line
next unless -r $file;
my $handle = IO::File->new($file, '<:utf8');
$self->_parse_context($line, [[<$handle>]]);
return $self;
}

# Parse specific file
return $self unless my $files = shift;
my @lines;
for my $lines (@$files) { push @lines, [split /\n/, $lines] }
my @lines = map { [split /\n/] } @$files;

# Clean up plain messages
return $self unless my $name = shift;
Expand All @@ -111,18 +94,15 @@ sub _detect {
$self->message($message);
}

# Parse message
# Find line
$name = quotemeta $name;
my $line;
$line = $1 if $self->message =~ /at\s+$name\s+line\s+(\d+)/;

# Stacktrace
unless ($line) {
if ($self->message =~ /at\s+$name\s+line\s+(\d+)/) { $line = $1 }
else {
for my $frame (@{$self->frames}) {
if ($frame->[1] =~ /^\(eval\ \d+\)$/) {
$line = $frame->[2];
last;
}
next unless $frame->[1] =~ /^\(eval\ \d+\)$/;
$line = $frame->[2];
last;
}
}

Expand All @@ -145,18 +125,14 @@ sub to_string {
$string .= $self->message if $self->message;

# Before
for my $line (@{$self->lines_before}) {
$string .= $line->[0] . ': ' . $line->[1] . "\n";
}
$string .= $_->[0] . ': ' . $_->[1] . "\n" for @{$self->lines_before};

# Line
$string .= ($self->line->[0] . ': ' . $self->line->[1] . "\n")
if $self->line->[0];

# After
for my $line (@{$self->lines_after}) {
$string .= $line->[0] . ': ' . $line->[1] . "\n";
}
$string .= $_->[0] . ': ' . $_->[1] . "\n" for @{$self->lines_after};

return $string;
}
Expand All @@ -175,10 +151,6 @@ sub _parse_context {
push @{$self->line}, $code;
}

# Cleanup
$self->lines_before([]);
$self->lines_after([]);

# Before
for my $i (2 .. 6) {
my $previous = $line - $i;
Expand Down Expand Up @@ -278,7 +250,8 @@ Raw unprocessed exception message.
my $verbose = $e->verbose;
$e = $e->verbose(1);
Activate verbose rendering.
Activate verbose rendering, defaults to the value of
C<MOJO_EXCEPTION_VERBOSE=1> or C<0>.
=head1 METHODS
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Message.pm
Expand Up @@ -495,7 +495,7 @@ sub _parse_formdata {
# Charset
my $charset = $part->charset || $default;

# "Content-Disposition"
# Content-Disposition header
my $disposition = $part->headers->content_disposition;
next unless $disposition;
my ($name) = $disposition =~ /\ name="?([^";]+)"?/;
Expand Down
14 changes: 6 additions & 8 deletions lib/Mojo/Template.pm
Expand Up @@ -584,7 +584,7 @@ build a wrapper around it.
$mt->template($template);
$mt->code($code);
$mt->compile;
my $output = $mt->interpret(@arguments);
my $output = $mt->interpret(@args);
=head1 ATTRIBUTES
Expand Down Expand Up @@ -774,7 +774,7 @@ Compile template.
=head2 C<interpret>
my $output = $mt->interpret;
my $output = $mt->interpret(@arguments);
my $output = $mt->interpret(@args);
Interpret template.
Expand All @@ -787,32 +787,30 @@ Parse template.
=head2 C<render>
my $output = $mt->render($template);
my $output = $mt->render($template, @arguments);
my $output = $mt->render($template, @args);
Render template.
=head2 C<render_file>
my $output = $mt->render_file($template_file);
my $output = $mt->render_file($template_file, @arguments);
my $output = $mt->render_file($template_file, @args);
Render template file.
=head2 C<render_file_to_file>
my $exception = $mt->render_file_to_file($template_file, $output_file);
my $exception = $mt->render_file_to_file(
$template_file, $output_file, @arguments
$template_file, $output_file, @args
);
Render template file to a specific file.
=head2 C<render_to_file>
my $exception = $mt->render_to_file($template, $output_file);
my $exception = $mt->render_to_file(
$template, $output_file, @arguments
);
my $exception = $mt->render_to_file($template, $output_file, @args);
Render template to a specific file.
Expand Down

0 comments on commit bd71622

Please sign in to comment.