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

IRC log for #mojo, 2017-08-29

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

All times shown according to UTC.

Time Nick Message
00:00 marty joined #mojo
01:00 rickbol joined #mojo
01:42 tchaves joined #mojo
01:51 ilbot2 joined #mojo
01:51 Topic for #mojo is now � nom nom | http://mojolicious.org | http://irclog.mojolicious.org | http://code-of-conduct.mojolicious.org
02:30 noganex joined #mojo
02:37 disputin joined #mojo
03:02 disputin joined #mojo
03:36 veryrusty joined #mojo
04:04 dboehmer_ joined #mojo
04:18 tchaves1 joined #mojo
04:25 tyldis mishanti1: Tried rocketchat and mattermost. Stuck with mattermost, but mainly because it's bundled with gitlab. LEss work
04:27 tyldis But rocket has had more features longer.
04:59 veryrusty joined #mojo
05:03 bit_shifter joined #mojo
05:39 inokenty-w joined #mojo
06:29 n16gel joined #mojo
06:55 veryrusty joined #mojo
06:56 AndrewIsh joined #mojo
07:30 trone joined #mojo
07:35 marty joined #mojo
07:43 prg joined #mojo
08:03 petru joined #mojo
08:22 kiwiroy joined #mojo
08:22 trone joined #mojo
08:34 rshadow joined #mojo
08:48 * CandyAngel has just realised she can use Mojolicious::Validation to valid data imported into her scripts :|
08:57 CandyAngel I wonder if I can quickly add it to this existing one..
09:00 mariusz joined #mojo
09:50 tohil joined #mojo
10:10 CandyAngel The answer is yes. Yes I can <3
10:31 n16gel joined #mojo
10:41 veryrusty joined #mojo
10:50 tchaves joined #mojo
10:56 tomred joined #mojo
11:07 veryrusty joined #mojo
11:25 castaway joined #mojo
12:05 veryrusty joined #mojo
12:26 gizmomathboy joined #mojo
12:45 bianca joined #mojo
12:56 dotan_convos joined #mojo
12:56 bianca Hey, can anyone explain how $c->session(expires => 1) works in mojolicious? I'm doing that in a post request, and then if I want to check if the user is logged in I am checking if $c->session('username') is defined. Which shouldn't be, because I just set it to expire, but it sometimes is defined and it contains the actual username. This is very confusing, would really appreciate some help. I pasted the relevant pieces of code here https://ideone.com/UUeYRw
12:57 kes joined #mojo
12:57 kes Hi. Why Mojolicious did not recognize the '_method' parameter?
12:57 kes what did I miss?
12:57 kes http://paste.scsys.co.uk/564992
13:00 kes the request in example is POST
13:03 bianca kes I don't think I understand entirely what your first 4 lines represent, but I'm seing you (correct me if I'm wrong) defined a route as `^\/pay/?(?:\.([^/]+))?$` and you say you are being redirected to http://localhost/invoices/pay?_method=PUT which is not the same thing since it doesn't have the '/' after pay. I might be wrong
13:04 kes the four lines before is output from bin/app routes -v
13:08 gryphon joined #mojo
13:08 kes trailing slash after pay is not required because of '?' after '/'. It is optional
13:09 kes same for this part too: (?:\.([^/]+))?
13:09 ragnar joined #mojo
13:09 CandyAngel bianca: As far as I know, it works by setting the cookie to expire, so maybe you are seeing a race condition (second request is coming though before logout has happened in the browser)
13:13 CandyAngel Or if it persists.. possibly the session is being expired, then created again from another connection?
13:14 bianca CandyAngel: when refreshing the page the session is still defined
13:14 bianca and it's only one connection, I'm on localhost..
13:14 itaipu joined #mojo
13:15 pink_mist what are you using to test?
13:15 pink_mist a webbrowser? curl? a script?
13:16 CandyAngel I'm guessing it is the latter then. Are you doing JS/AJAX stuff?
13:17 bianca yes, I am doing the post in jquery. I thought it wasn't relevant since I'm seing the session defined on the server.. Actually here is what happened after an unsuccessful logout and a page refresh. I'm using chrome
13:17 bianca https://ideone.com/4szoUZ
13:18 CandyAngel If A requests logout and B requests /page at the same time, the server might process A first (expiring the session), then create the session cookie again when it responds to B
13:20 bianca CandyAngel: I am only doing one action at the time, there is no concurrency. I'm only doing a logout.. Or what do you mean by A and B?
13:21 CandyAngel A and B are the requests to the server from JS or whatever
13:21 kes I think he mean concurrency
13:22 CandyAngel Aren't HTTP requests through jQuery always async?
13:23 bianca https://ideone.com/UUeYRw I added the frontend code here
13:24 bianca this shows an alert with Data:  '{success: "true"}' everytime, regardless of if I was logged out or not
13:26 karjala_ joined #mojo
13:27 CandyAngel Have you tried returning 0 in is_logged_in?
13:28 CandyAngel Or undef even
13:29 bianca I'll try that now
13:29 kes heh... I have empty action in controller: sub pay {}
13:30 CandyAngel Wait.. your under is very different to the one in the documentation
13:30 CandyAngel http://mojolicious.org/perldoc/Mojolicious/Guides/Routing#Under
13:31 CandyAngel You have: $r->under('/')->to(..
13:32 CandyAngel Rather than: $r->under('/' => sub { .. });
13:32 CandyAngel So it is always matching, I think..
13:33 kes Is it will be useful if on error page Mojo will display why 404 occur: 1. No action found; 2. No template found; 3. No route found at all. Sometime this info will save time
13:33 bianca kes: glad you solved it :)
13:34 karjala_ kes, I think this information is displayed in the far bottom of the error page
13:34 bianca CandyAngel: The first example is defined as $r->under('/foo')->to('foo#baz');
13:34 karjala_ kes, where some log lines appear, saying things like "template not found" etc
13:34 bianca which is what I'm doing
13:36 bianca CandyAngel: I believe I have to return 1 on success since otherwise nothing will get rendered there (If I'm returning undef)
13:36 bianca I'll try to do it as in that example and see what happens
13:37 kes bianca: with Devel::DebugHooks you may put breakpoints in your Mojo code and see what is coming on
13:37 kes If you have questions on that module I may help
13:38 CandyAngel Yeah, sorry, I meant change the "return;" when it fails to "return undef;"
13:42 CandyAngel Personally, I would watch the conversation between the client/server with wireshark and see what cookies are being sent/set when :P
13:42 CandyAngel Not sure if MOJO_DAEMON_DEBUG=1 will show it..?
13:43 bianca kes: and CandyAngel: thanks, I'll try those out and maybe I'll find the cause. Since it's only failing sometimes, it might be some async issue as you suggested..
13:50 bianca CandyAngel: Actually it might be what you suggested earlier, with A not finishing before B gets to execute. I have in the frontend an 'a' tag which requests the current page, which means that I have the logout request at the same time as the other one
13:51 bianca <a href="" onclick='do_logout();'>
13:51 bianca I probably should not do that...
13:53 kes you may check if does that happen or not. Add 'alert("Logout")' like this: <a href="" onclick='alert("Logout");do_logout();'>
13:55 kes I want to create validation check or filter which requires access to model. What is the best way to call $c->model from there?
13:56 kes I can not find how to access $c from there.
14:00 kes may you recommend something?
14:00 mcsnolte joined #mojo
14:01 bianca kes: maybe passing the controller as a parameter to the function? That's how I'm doing validations, validate_field($c, $field);
14:02 kes yeah, but 'filter' did not support parameters
14:08 CandyAngel bianca: Ah, so the <a> fires at the same time as the do_logout()?
14:08 CandyAngel And without a target, gets the current page?
14:08 bianca basically yes
14:08 CandyAngel s/target/href/
14:08 CandyAngel Awesome
14:08 kes $validation->required( 'invoice_id', [ data_exists => $c, 'Invoice' ], 'filter2' )
14:09 kes where 'data_exists' is first filter and $c, 'Invoice' are arguments to it
14:09 kes would be this useful?
14:10 CandyAngel Oh, you are providing a href, just a blank one. Might work better if you remove that..
14:10 CandyAngel <a onclick="...">
14:10 mib_t72h6w joined #mojo
14:11 haarg without an href they don't won't get formatted as links (unless you do it yourself)
14:13 CandyAngel Oh yeah, so it does..
14:13 bianca I added the alert(); before calling the logout in on_click and I tested several times and it worked so far, so I'm guessing that removes the race condition. Or maybe it was just chance and next time it will fail again
14:13 CandyAngel Oh.. yeah, I think you should do umm
14:13 CandyAngel <a href="#" onclick="..">
14:14 haarg the common thing used to be doing <a href="#" onclick="...; return false;">
14:14 CandyAngel That won't request a page through the anchor, but will format as one
14:14 CandyAngel I think it scrolls to the top of the page though?
14:14 haarg return false means it doesn't follow the link
14:14 CandyAngel Ah, coolies
14:14 CandyAngel That's useful to know!
14:14 bianca that shoudn't be a problem since I am displaying a different page afterwards
14:14 haarg newer things often end up using <button> and formatting like a link instead
14:15 CandyAngel If you are moving to a different page, why use JS?
14:15 bianca how would you do it?
14:16 CandyAngel Just request /logout and then have it redirect to the page you want them to land on afterwards
14:18 CandyAngel So you would have in "sub on_logout": $self->session(expires => 1); $self->redirect_to('thanksforvisiting');
14:18 bianca so you would have logout be a get request?
14:18 CandyAngel Yup
14:18 bianca that might just be way easier
14:19 bianca I was thinking logout should be post, since I'm not requesting anything
14:20 jberger you could make it a tiny form, submitted as post, if you like
14:23 CandyAngel bianca: POST is for sending extra data, which you are not doing either :)
14:23 CandyAngel GET is fine for this
14:23 bianca yeah that's right ;)) I'll just leave it be get, it's easier
14:23 bianca and works well
14:23 haarg is really should be a post but eh
14:23 jberger CandyAngel: in some sense, POST more RESTful, since GET is supposed to be idempotent and a logout is not
14:24 jberger but honestly, I usually just do login/logout as kinda separate from the rest of my api
14:26 CandyAngel jberger: with race conditions, POSTed logout isn't idempotent either :)
14:28 jberger with race conditions, all just we might home go
14:28 jberger :-P
14:29 CandyAngel That was.. perfect
14:29 CandyAngel Also, how would you go about that? Put an id in the cookie and keep session state on the server..?
14:30 CandyAngel about fixing that..
14:31 jberger I'm not sure I understand the question
14:31 CandyAngel Oh.. bianca's logout function was under a session check, so when they expired the cookie, the second request recreated it
14:32 CandyAngel Er, hold on
14:32 CandyAngel Mixed 2 thoughts then :P
14:32 CandyAngel A and B requests sent at the same time to Mojo (so both have session cookies), A's request expires the cookie, but B's request creates a new one..
14:33 bianca I don't fully understand that
14:33 bianca why the session is recreated
14:34 CandyAngel Because B sent a valid session cookie to Mojo, so Mojo tells it to set a new session cookie with an updated (in the future) expiry
14:34 CandyAngel Mojo doesn't know that it expired it for A
14:35 kes karjala_: I was confused by: "maybe you need to add a new one?" which is in the top of error page
14:36 CandyAngel A(valid session) B(valid session) -> A(expired session) B(updated valid session)
14:37 kes So "maybe you need to add a new template" will be better in case when action exist and route happen
14:37 petru joined #mojo
14:39 jberger ok so I just reread and I now see the original problem, and yes it is likely due to concurrent requests
14:39 jberger and I think the answer is ... don't do that :-P
14:39 CandyAngel As far as I can tell, the only way to prevent this is to have server-side state and some value in the session you can check sessions are still valid from that
14:40 jberger like you all were saying, prevent the default handling of the link if you are using js to logout
14:40 CandyAngel In theory, if you can make requests at the right time, you can do this with any Mojo app using sessions :P
14:40 jberger to be more proactive, yes you would probably need to have server-side state
14:40 CandyAngel (log out without being logged out)
14:41 jberger that's the fun of cookies and client-side state
14:41 CandyAngel And concurrency :)
14:41 jberger I suppose you could just have your javascript dump your cookie
14:42 jberger even that still doesn't prevent an already in-progress request from re-inflating your session though
14:45 marty joined #mojo
15:10 disputin joined #mojo
15:30 CandyAngel Hmm.. while I can use validation on this CSV input, I think it might be a bit unwieldy.. what is required (and what values are valid) depend on other fields
15:32 ChmEarl joined #mojo
15:45 Grinnz those who have asked about porting mojo to perl 6, this kind of seems like a toolkit of similar spirit http://cro.services/
15:52 karjala_ joined #mojo
16:05 tcohen joined #mojo
16:07 sh14 joined #mojo
16:13 brunoramos joined #mojo
16:15 Pyritic joined #mojo
16:47 petru joined #mojo
16:55 disputin joined #mojo
17:10 Pyritic joined #mojo
17:26 PopeFelix joined #mojo
17:34 gryphon joined #mojo
17:47 PopeFelix Dumb question, maybe, but in a Mojo controller, when it gets HTTP input, the data are encoded into Perl's native character encoding from whatever the specified encoding was, right?
17:48 Grinnz no, it's decoded to characters
17:48 PopeFelix decoded to Perl characters?
17:48 Grinnz just... characters
17:48 PopeFelix Perl native characters, I mean
17:48 pink_mist just characters
17:48 Grinnz U+XXXX U+YYYY
17:48 Grinnz characters are an abstract representation
17:49 Grinnz how perl actually stores them during program runtime is unrelated
17:50 Grinnz you should always be working with characters, decoded from input and encoded for output
17:50 Grinnz mojo mostly does those automatically
17:50 PopeFelix OK. That's what I wanted to know. If I needed to decode the input myself, or if Mojo did that for me.
17:54 jberger if you use $res->body it is bytes if you use $res->text it is characters
17:54 PopeFelix ahhhh
17:55 PopeFelix Good to know, thanks jberger
17:56 jberger http://imgur.com/IW8simF
17:57 PopeFelix lol
18:10 bianca joined #mojo
18:29 Pyritic joined #mojo
19:05 tcohen anyone with experience writing unit tests for mojo plugins?
19:06 tcohen need some pointers
19:07 dustinm joined #mojo
19:08 Pyritic joined #mojo
19:10 FROGGS joined #mojo
19:16 perlpilot_ joined #mojo
19:20 cfedde Test::MOjo?
19:22 n16gel joined #mojo
19:22 jberger tcohen: as cfedde says, make a dummy application and load the plugin into it, then just test with Test::Mojo as usual
19:32 tcohen jberger, cfedde thanks, I was just doing that, stealing some sample from existing plugins :-D
19:33 cfedde Amateurs copy, professionals steal.
19:34 tcohen indeed, LOL
19:36 n16gel joined #mojo
19:37 n16gel joined #mojo
19:48 tcohen I love writing tests thanks #mojo
19:49 Grinnz i love writing tests until i write modules doing things that are really annoying to test
19:49 Grinnz which is most of the modules i write, for some reason
19:58 cfedde rethink the modules sl that are easy to test.
19:58 cfedde s/sl/so/
20:05 Grinnz to make them easy to test, we'd need to rethink how operating systems work first
20:16 petru joined #mojo
20:23 n16gel joined #mojo
20:57 jberger that might be worth doing (and less work)
20:57 jberger don't worry systemd will do that for you anyway before its done though
21:04 * cfedde goes back to trying to make windows 10 into a usable desk top environment.
21:06 genio poor cfedde. it was nice knowing him... *sniff*
21:08 cfedde it's surprising how bad the linux subsystem is.
21:08 cfedde bad enough that I start customizing putty.
21:11 jberger is it bad or is it just the cmd.exe terminal interface?
21:11 cfedde I think that's really the issue.
21:12 genio yea, the terminal interface leaves a LOT to be desired
21:12 cfedde Microsoft continues it's tradition of making pesimal choices on basic defaults.
21:12 pink_mist cygwin comes with a nice bash and a decent terminal
21:12 jberger but that's always been true, now at least you get to use a reasonable system once you're typing
21:14 cfedde putty + some vm makes a better jump box than the linux subsystem does.  Exactly because of the cmd.exe behavior.
21:14 jberger https://github.com/mintty/wsltty ?
21:14 Grinnz i'm just using my work box as a way to start vmware these days
21:15 Grinnz with a real operating system inside
21:15 jberger ugh, that uses cygwin to talk to WSL
21:15 jberger WHHHHYYYYYYYYYYY?!?!
21:15 pink_mist well, mintty is the cygwin terminal emulator
21:15 pink_mist so I'm not surprised
21:16 cfedde that might be easier than starting an X11 and using gnome-terminal.
21:17 jberger http://cmder.net/
21:18 cfedde reporting experience or interesting links?
21:18 rickbol joined #mojo
21:18 jberger just links
21:18 jberger I don't touch windows with a ten foot pole
21:18 Grinnz some of my coworkers use cmder i think
21:18 * cfedde is still wondering why people stopped using paper terminals.
21:19 jberger but I empathize with those that have to
21:20 kiwiroy joined #mojo
21:22 cfedde thanks for the links.
21:23 cfedde One nice thing about working for the evil empire is that we have good bandwidth.
21:24 trone joined #mojo
21:25 disputin joined #mojo
21:26 disputin joined #mojo
21:32 stryx` joined #mojo
21:32 orev joined #mojo
22:01 kiwiroy joined #mojo
22:22 rickbol joined #mojo
22:25 dantti_laptop joined #mojo
22:27 kiwiroy joined #mojo
22:36 kiwiroy joined #mojo
22:42 rickbol joined #mojo
23:05 rickbol joined #mojo
23:20 genio cmder just wraps cmd.exe or whatever in a tabbed environment
23:20 genio there is no sane option for windows
23:27 CandyAngel Sooo.. I switched to Palemoon because Firefox going PA audio meant no audio from Firefox.. but I don't think Palemoon will work with my setup either (sometimes, audio/video will play at 3-10x speed)
23:28 CandyAngel And I don't think PA will do what I want either -.-
23:29 Grinnz embrace audiod
23:29 CandyAngel Not seen the speedup in Chromium though, so maybe it is something I can help fix in Palemoon
23:32 rickbol joined #mojo
23:34 CandyAngel All I want is this: http://www.plantuml.com/plantuml/png/qt1CJiulpIjHCD9KqBLJqF18JKmfJYtHvD90a_39poz8IapE1ih0cM09VwTW9DM6gCO00000
23:34 CandyAngel And it all works fine, except Palemoon :P
23:36 Grinnz oh man, trying to get a complex audio arrangement to work is the worst
23:36 Grinnz it was worse before OBS studio made things simpler with desktop audio
23:37 CandyAngel Well, it took me like.. 15 minutes to get it "working", then 4 hours trying to get Palemoon to work properly :P
23:37 CandyAngel And I still haven't managed it
23:38 Grinnz i wasted an hour or so recently trying to get a streaming setup to work when the audio kept turning into a buzzing mess, until i realized its because the game was set to dolby digital and my capture card couldnt handle that
23:38 CandyAngel Ouch :\
23:39 Grinnz i thought it was just typical device driver issues
23:39 Grinnz because well, that's been a problem a lot
23:42 Grinnz and honestly pulseaudio has made it all a lot simpler, cause i dont have to learn how to configure alsa anymore
23:42 Grinnz but the rare times when pulse doesn't "just work" sucks
23:52 CandyAngel I've had one case where it not "just working" wasn't too bad
23:52 CandyAngel Just had to set a different default sink or something (1 line in config/startup file or something)
23:53 CandyAngel But yeah, the rest of the time, sounds stopped working? PA got installed

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