Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mojo::Transaction::WebSocket::send forces stringification on object #470

Merged
merged 1 commit into from
Mar 21, 2013

Conversation

jberger
Copy link
Member

@jberger jberger commented Mar 21, 2013

Allows send to stringify an object. This especially helps for Mojo::ByteStream objects returned by render_partial.

@jberger
Copy link
Member Author

jberger commented Mar 21, 2013

The use case (presented by @marcusramberg) is

$app->helper(
  send_partial => sub { 
    my $self = shift; 
    $self->send( $self->render_partial(@_) );
  }
);

which currently fails with the not-so-helpful message

Event "read" failed: Not an ARRAY reference at /Users/marcus/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/Mojo/Transaction/WebSocket.pm line 209.

In actually you don't want an array reference (a user reading this might surround the call with [] which would attempt to send a raw websocket frame and almost certainly not do what you mean), you want to force stringification

$app->helper(
  send_partial => sub { 
    my $self = shift; 
    $self->send( $self->render_partial(@_) . '' );
  }
);

But with this patch the first example works correctly

kraih added a commit that referenced this pull request Mar 21, 2013
Mojo::Transaction::WebSocket::send forces stringification on object
@kraih kraih merged commit 12fb487 into master Mar 21, 2013
@kraih kraih deleted the ws_send_stringify branch March 21, 2013 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants