Skip to content

Commit

Permalink
fixed transaction builder
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 11, 2011
1 parent 702f19c commit 7511dd5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
24 changes: 12 additions & 12 deletions lib/Mojo.pm
Expand Up @@ -35,12 +35,12 @@ sub new {
return $self;
}

sub build_tx { Mojo::Transaction::HTTP->new }

# "D’oh."
sub handler { croak 'Method "handler" not implemented in subclass' }

sub transaction { Mojo::Transaction::HTTP->new }

sub upgrade { Mojo::Transaction::WebSocket->new(handshake => pop) }
sub upgrade_tx { Mojo::Transaction::WebSocket->new(handshake => pop) }

1;
__END__
Expand Down Expand Up @@ -124,6 +124,13 @@ Construct a new L<Mojo> application.
Will automatically detect your home directory and set up logging to
C<log/mojo.log> if there's a C<log> directory.
=head2 C<build_tx>
my $tx = $app->build_tx;
Transaction builder, defaults to building a L<Mojo::Transaction::HTTP>
object.
=head2 C<handler>
$tx = $app->handler($tx);
Expand All @@ -136,16 +143,9 @@ L<Mojo::Transaction::HTTP> or L<Mojo::Transaction::WebSocket> object.
my ($self, $tx) = @_;
}
=head2 C<transaction>
my $tx = $app->transaction;
Transaction builder, defaults to building a L<Mojo::Transaction::HTTP>
object.
=head2 C<upgrade>
=head2 C<upgrade_tx>
my $ws = $app->upgrade(tx);
my $ws = $app->upgrade_tx(tx);
Upgrade transaction, defaults to building a L<Mojo::Transaction::WebSocket>
object.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Server.pm
Expand Up @@ -23,13 +23,13 @@ sub new {
$self->on_transaction(
sub {
my ($self, $txref) = @_;
$$txref = $self->app->transaction;
$$txref = $self->app->build_tx;
}
);
$self->on_upgrade(
sub {
my ($self, $txref) = @_;
$$txref = $self->app->upgrade($$txref);
$$txref = $self->app->upgrade_tx($$txref);
$$txref->server_handshake;
}
);
Expand Down
28 changes: 14 additions & 14 deletions lib/Mojolicious.pm
Expand Up @@ -107,6 +107,13 @@ sub new {
return $self;
}

sub build_tx {
my $self = shift;
my $tx = Mojo::Transaction::HTTP->new;
$self->plugins->run_hook(after_build_tx => $tx, $self);
return $tx;
}

# "Amy, technology isn't intrinsically good or evil. It's how it's used.
# Like the Death Ray."
sub defaults {
Expand Down Expand Up @@ -225,13 +232,6 @@ sub start {
# This will run once at startup
sub startup { }

sub transaction {
my $self = shift;
my $tx = Mojo::Transaction::HTTP->new;
$self->plugins->run_hook(after_build_tx => $tx, $self);
return $tx;
}

1;
__END__
Expand Down Expand Up @@ -404,6 +404,13 @@ Will automatically detect your home directory and set up logging based on
your current operating mode.
Also sets up the renderer, static dispatcher and a default set of plugins.
=head2 C<build_tx>
my $tx = $app->build_tx;
Transaction builder, defaults to building a L<Mojo::Transaction::HTTP>
object.
=head2 C<defaults>
my $defaults = $app->defaults;
Expand Down Expand Up @@ -615,13 +622,6 @@ startup.
my $self = shift;
}
=head2 C<transaction>
my $tx = $app->transaction;
Transaction builder, defaults to building a L<Mojo::Transaction::HTTP>
object.
=head1 HELPERS
In addition to the attributes and methods above you can also call helpers on
Expand Down

0 comments on commit 7511dd5

Please sign in to comment.