The web in a box - a next generation web framework for the Perl programming language

IRC log for #mojo, 2017-08-26

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
00:23 Lee joined #mojo
00:27 Grinnz in the last couple webapps i've used, i use current_route heavily
00:27 Grinnz and usually explicit route names
00:27 Grinnz er, webapps i've written*
00:44 VVelox joined #mojo
01:24 Lee joined #mojo
02:25 Lee joined #mojo
02:33 noganex_ joined #mojo
02:45 VVelox joined #mojo
03:26 Lee joined #mojo
03:37 karjala_ joined #mojo
04:04 dboehmer joined #mojo
04:27 Lee joined #mojo
05:10 VVelox_ joined #mojo
05:28 Lee joined #mojo
05:40 marty joined #mojo
06:08 Lee joined #mojo
06:52 inokenty joined #mojo
07:08 Lee joined #mojo
07:12 karjala_ joined #mojo
07:33 petru joined #mojo
08:29 leffe joined #mojo
08:29 leffe hi again! :)
08:30 leffe Question How do I mock the controller class. I have some helpers I want to test.
08:31 leffe I don't know if I can just instantiate it and put some values in it, I just want to see if it has a value in flash ..
08:31 preaction $t->app->build_controller can get you a plain controller, and then you can put values in it
08:31 leffe what is t?
08:32 preaction the Test::Mojo instance
08:33 leffe ok ! great so I should write my $t = Test::Mojo->new ; my $c = $t->app->build_controller ; $c->flash( something => 'value')
08:33 leffe right?
08:56 leffe $t->app is undef when I instantiate Test::Mojo with no args
08:56 leffe What I'm doing wrong?
09:16 leffe How do I mock the controller to test a helper in isolation? Does mojolicious provide these mocks, or can I just instantiate a controller and pass values?
09:29 preaction create a new app (Mojolicious->new), add the helper to it, give that to Test::Mojo
10:09 Vandal joined #mojo
11:43 tuman joined #mojo
12:19 Alex342 joined #mojo
12:22 Alex342 Hei guys. I want to create a filter for my submissions, but i dont know how. I tried this https://pastebin.com/qKkR4DPj
12:22 Alex342 Doen t work :)))
12:25 Alex342 Any advice?
12:52 trone joined #mojo
12:58 Alex342 :(
13:02 CandyAngel The "return shift" is returning undef?
13:03 CandyAngel Oh wait, no it isn't
13:05 Alex342 i want to do smth like     return shift->find( {problem -> pop} );
13:05 CandyAngel However, you are popping twice
13:05 Alex342 I can't do that?
13:06 CandyAngel Well, I presume @_ is ($self, $author) at the start
13:06 CandyAngel In the first if, you pop which makes it ($self)
13:06 CandyAngel You want something like
13:07 CandyAngel return shift if $_[1] eq '';
13:07 CandyAngel return shift->search(undef, {author => pop});
13:08 CandyAngel I wouldn't do that personally, I'd unpack @_ to ($self, $author), but I think the above will work
13:08 Alex342 but the search remain unchanged...Why should it work now?
13:09 CandyAngel At the start of the sub, @_ contains ($resultset, $author), right?
13:10 Alex342 yes
13:10 CandyAngel Your first "if" is removing $author from @_
13:10 sh14 joined #mojo
13:10 CandyAngel So if it isn't '' and falls through, @_ will only contain ($resultset)
13:12 CandyAngel So doing shift/pop again will make one of them "undef"
13:12 CandyAngel Because one will take the $resultset, then there will be nothing for the other one
13:31 abra joined #mojo
13:37 abra joined #mojo
14:20 ChmEarl joined #mojo
14:21 gizmomathboy joined #mojo
14:42 marty joined #mojo
14:47 Alex342 joined #mojo
15:15 leffe joined #mojo
15:15 leffe Hi again :)
15:17 leffe I have come with a solution for mocking Mojolicious objects ...
15:17 leffe the controller. to be more specific
15:18 leffe whenever I need to test something like a helper, where i need the controller.
15:18 leffe I write a mock on the fly like this
15:20 leffe my $flash_value; $c = do {     package Mock::Mojolicious::Controller;     sub flash { $flash_value };     bless {}; } ;
15:20 leffe then I use the object c in the helper call like this
15:21 leffe $flash_value = 'ok'; like XmediaLite::Helpers::success( $c ), qr/Cambios guardados con éxito/     => "success() when '{success => ok} stored in flash";
15:21 leffe $flash_value = undef; ok ! defined  XmediaLite::Helpers::success( $c )     => "success() when 'success' is not stored in flash";
15:22 marty_ joined #mojo
15:23 leffe That is, I create an object with just the methods I need. And then use it to test my Mojolicious app components.
15:24 leffe I don't know how perl folks do this. That is, mocking Mojolicious::Controller objects to test components isolated from the rest.
15:26 leffe When I programmed in java I subclassed the components I did not want to test, and rewrote the methods I was interested in ...
15:26 petru joined #mojo
15:26 leffe This worked fine for me, I never used any Mocking framework.
15:27 Alex342 joined #mojo
15:27 leffe Is ok what I'm doing to test Mojolicious apps, or is there an easier way, or canonical way of doing this?
15:35 marty joined #mojo
16:02 eseyman joined #mojo
16:04 karjala_ joined #mojo
16:23 n16gel joined #mojo
16:35 Alex342 joined #mojo
16:40 marty joined #mojo
16:48 bit_shifter joined #mojo
17:01 bit_shifter joined #mojo
17:06 karjala_ joined #mojo
17:35 leffe joined #mojo
17:37 bit_shifter joined #mojo
17:58 bit_shifter Trying to create a persistent websocket connection to another web service's ws server, and ensure the ws connection is established before serving HTTP responses to my app's clients.  Not sure how to delay response until the ws connection is established.  Thoughts? http://sprunge.us/dWJb?pl
18:00 preaction bit_shifter: set a flag in the websocket connect event. check for that flag in your response handler. if flag exists, websocket is established, use websocket to do thing. if flag not exists, add another connect event handler (using once() so it gets removed), in new connect event handler, use websocket to do thing
18:01 preaction i'll bet there's even already a flag in the Mojo::Transaction::WebSocket class
18:03 bit_shifter http://mojolicious.org/perldoc/Mojo/Transaction/WebSocket#established looks like a good indicator.
18:04 bit_shifter By "connect event handler", do you mean something like "$tx->on(connect => sub {...})"?
18:04 preaction yes
18:05 preaction the name of the event is "connect", so the sub is a connect event handler
18:07 bit_shifter Just adding "$tx->on(connect => sub { say 'CONNECTED'; });
18:07 bit_shifter doesn't seem to do anything, inside the websocket() call.  Is that wrong?
18:08 bit_shifter Trying to find the docs for the class that emits "connect"
18:11 bit_shifter I did find http://mojolicious.org/perldoc/Mojo/Transaction#connection but changing connect to connection doesn't seem to have an effect either.
18:12 preaction sorry, it's the sub in your paste that starts on line 15, so you might have to keep track of the things you have to do yourself
18:12 bit_shifter Yeah, that's where I put it.
18:12 preaction it'll likely be easier if you make your helper `ws_send` instead
18:13 preaction the connect handler is the sub that starts on line 15. there is no "connect" event, i was wrong
18:13 preaction so, if you want to queue up things to do when the connect handler runs, you'll need to do that yourself
18:13 bit_shifter Ah
19:15 bit_shifter joined #mojo
19:21 jberger bit_shifter don't return the $ws call a callback instead
19:22 jberger You have to use nonblocking patterns here
19:30 mariusz joined #mojo
19:33 bit_shifter Does this seem reasonable?  This is what I've come up with so far: http://sprunge.us/TjZf?pl
19:34 jberger haven't looked yet, here was mine: http://paste.debian.net/983151/
19:34 jberger I think the queue was more than you needed, tbh
19:35 jberger note of course that mine isn't tested as I don't have your templates
19:36 jberger also I don't get what you are trying to do by sending on a ws AND rendering html in the same action
19:37 jberger I think once you get your non-blocking bits figured out, I don't think you need the queue concept at all here
19:38 bit_shifter My app is a ws client for a separate backend service, in addition to serving HTTP (maybe this will change to ws too) to clients.
19:38 bit_shifter Yeah, I like your solution.
19:38 jberger also, I think people confuse themselves with routes that server both a GET and websocket in the same action
19:38 jberger yes that is POSSIBLE, but until you are really comfortable, I'd suggest make those two separate routes
19:39 jberger get '/' => sub { # render html }; websocket '/ws_route' => sub { # do ws stuff }
19:39 jberger plus that probably even lets you get rid of the ws helper which though it should work is ALSO probably more than you need
19:39 jberger and actually, the more I think about it
19:40 jberger state $ws is a bad pattern
19:40 jberger it only works for one client per server process
19:40 bit_shifter My server IS the ws client in this app.
19:40 bit_shifter My clients are HTTP for now
19:40 jberger sorry, it took me a moment to get there
19:41 jberger ?
19:41 jberger you have the server connecting back to the server over websocket?
19:41 bit_shifter A different server
19:41 bit_shifter Running on the same machine
19:41 bit_shifter Someone else's code (mopidy)
19:41 jberger ok, so you don't want state
19:42 jberger you want to stash the websocket connection
19:42 jberger but at least the rest of it makes more sense to me now
19:43 bit_shifter If I stash the ws connection, it will still listen for events?
19:44 karjala_ joined #mojo
19:45 jberger http://paste.debian.net/983154/
19:45 jberger sure
19:45 jberger it is in the ioloop
19:45 jberger you just stash it for recovery later
19:45 jberger (and to keep the connection alive)
19:46 bit_shifter Oh, interesting
19:46 jberger and actually, you need to keep the transaction related to $c alive too someplace
19:47 jberger hmmmm, I guess I still don't understand what the websocket connection is doing
19:47 bit_shifter Retrieving backend data to pass on to my (many) clients
19:48 jberger yeah, but once the HTML is rendered that connection is basically gone
19:48 bit_shifter Yeah, I might have to do ws for my clients?
19:48 jberger (might be kept-alive, but from your perspective)
19:51 bit_shifter Once the initial backend ws connection is established I can just do ajax or ws on the client side.
20:01 jberger how can you talk back to the the ws connection via ajax? mostly meaning, how do you address it?
20:01 jberger how does the server know which connection to give you?
20:03 bit_shifter My server only needs one connection to the mopidy backend as my app is a shared app (a jukebox) between my clients.
20:04 bit_shifter My clients will do ajax to my app which will translate it to the appropriate ws calls to mopidy and return that data.
20:12 petru joined #mojo
20:31 eseyman joined #mojo
21:33 marty joined #mojo

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary