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

IRC log for #mojo, 2017-07-12

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

All times shown according to UTC.

Time Nick Message
00:21 Pierre joined #mojo
00:40 tchaves joined #mojo
01:04 zivester joined #mojo
02:08 noganex_ joined #mojo
02:13 foursixnine joined #mojo
02:13 Caldrin joined #mojo
02:13 Andreas2 joined #mojo
02:38 gryphon joined #mojo
02:46 Pierre joined #mojo
03:29 Pierre joined #mojo
03:32 stryx` joined #mojo
04:17 bc547 joined #mojo
04:23 Pierre joined #mojo
04:57 sh14 joined #mojo
05:03 inokenty-w joined #mojo
05:47 cosimo joined #mojo
06:00 Pierre joined #mojo
06:45 karjala_ joined #mojo
06:49 Pierre joined #mojo
06:51 AndrewIsh joined #mojo
06:53 dod joined #mojo
06:55 dod joined #mojo
07:09 dod joined #mojo
07:29 VVelox joined #mojo
08:32 Vandal joined #mojo
08:38 zen .win 14
08:39 rshadow joined #mojo
09:15 ashimema joined #mojo
09:32 nic joined #mojo
09:46 dod joined #mojo
09:55 dod1 joined #mojo
10:50 gregf_ joined #mojo
12:13 tchaves joined #mojo
12:13 dod joined #mojo
12:22 dod1 joined #mojo
12:27 dod joined #mojo
12:41 mattp_ joined #mojo
12:45 cosimo joined #mojo
12:51 gizmomathboy joined #mojo
12:54 Pierre joined #mojo
12:59 dod1 joined #mojo
13:13 Pyritic joined #mojo
13:20 gryphon joined #mojo
13:28 gizmomathboy joined #mojo
14:13 [vlad] joined #mojo
14:26 VVelox joined #mojo
14:30 karjala_ joined #mojo
14:57 mcsnolte joined #mojo
15:00 tchaves Hello guys!
15:00 tchaves I would like your help with Mojo::JWT. I currently use Mojolicious::Plugin::Authentication in my applications and am trying to use it now with JWT authentication, but I have some doubts.
15:00 tchaves Is JWT authentication to be used only for routes in APIs and in normal authentication do I continue to use Mojolicious::Plugin::Authentication?
15:01 tchaves Or not, to use JWT should I just use Mojo::jWT leaving out Mojolicious::Plugin::Authentication?
15:01 tchaves Can anyone help me with this explanation?
15:01 tchaves Thanks
15:03 sri i think most consider Mojolicious::Plugin::Authentication to be useless
15:05 jberger author of Mojo::JWT here, I use it without M::P::Authentication
15:05 jberger and indeed I don't use that plugin at all
15:05 jberger oh sidenote!
15:06 jberger Mojolicious::Plugin::OpenAPI just gained the ability to do OpenAPI-spec-ed authentication
15:06 sri every time Mojolicious::Plugin::Authentication comes up i ask how it is useful... and i never get an answer
15:07 sri i'd even accept it as a plugin with documentation focus (teaching authentication), but it really doesn't do a good job there at all
15:10 gizmomathboy joined #mojo
15:10 tchaves Got it
15:11 sri so, what's up with VS Code getting so much buzz?
15:11 sri is it really that good?
15:15 zivester joined #mojo
15:24 spicyjack sri: I know a few people who use it, they like it a lot over something like IntelliJ
15:24 spicyjack sri: Mac users
15:24 purl Mac users is blech or lamech or Theory
15:24 spicyjack sri: the support for rust-lang is good, I haven't seen it being used for other languages
15:26 jberger I keep meaning to try IntelliJ with the CamelCade perl support that keeps showing up on reddit
15:26 jberger latest one supposedly introduced Mojo-specific stuff
15:51 Grinnz it works well for me, I suppose atom would too but I never tried it
15:52 karjala_ joined #mojo
15:52 sri vscode feels a bit more snappy, but also rather unpolished
16:05 bc547 joined #mojo
16:07 PryMar56 joined #mojo
16:33 jabberwok joined #mojo
16:36 sirhalos joined #mojo
16:37 sirhalos Hello, I'm looking for some help with my upload method. Is there anything that stands out that I am doing incorrectly? https://pastebin.com/1drHCsFs
16:39 Grinnz sirhalos: rendering both json and text doesn't make any sense
16:39 Grinnz also if you use the json generator, you would pass it a hash reference, not a string
16:43 sirhalos Currently I'm getting an error about my $mime where can't call method "headers" on undefined value.
16:43 sirhalos If I take out 'pdf' from $self->req->upload(); it just hangs
16:43 sirhalos I don't have a frontend right now, just testing with a restclient
16:44 sirhalos I was trying to get multiple renders json/text since that is how a lot of api is here at work, depending on the programmer and their level how the want to parse the api. Shell people want text or csv, web people want json always.
16:46 pink_mist sirhalos: you can cater to them by having Mojolicious render the right thing using hints from fileendings, so if your endpoint if http://example.com/foo.json it'll render json, and http://example.com/foo.txt would render text
16:47 pink_mist *endpoint is
16:47 sirhalos Okay thanks, I'll think about doing that.
16:48 sirhalos Right now I'm just needing to get a basic upload route working. I tried Mojo::Upload instead but I had less luck with looking at what was going on with Data::Dumper
16:48 Grinnz you can use the stash value 'format' to find what they passed: https://metacpan.org/pod/Mojolicious::Guides::Routing#Formats
16:49 Grinnz or you can have them pass an Accepts header and check that
16:49 sirhalos Thanks for the link.
16:49 Grinnz Data::Dumper isn't always very useful for introspecting objects
16:50 Grinnz you should check that $pdf is defined before calling methods on it
16:50 Grinnz e.g. return an error message if they didn't actually upload something called 'pdf'
16:50 sirhalos I won't know the PDF name
16:50 sirhalos it isn't multipart either
16:51 Grinnz it's not the pdf name, it's the form field name
16:51 sirhalos this post will be just simple they send a PDF and filesize can be anything
16:51 sirhalos okay that's what I thought
16:51 Grinnz if they're sending the pdf as the entire content, then don't use ->upload to get it... you would use ->body
16:51 sirhalos Like this? $self->req->body('pdf');
16:52 Grinnz it would be just data, you wouldn't get any metadata for it as you would if it was a form submission
16:52 Grinnz no, just ->body;
16:52 Grinnz if you want to check the content type of the request itself, check $self->req->headers->content_type
16:52 sirhalos Okay
16:59 sirhalos When I do $self->body('pdf'); I get Can't locate object method 'body'.
16:59 Grinnz $self->req->body;
16:59 Grinnz no argument
17:01 sirhalos Now I get Can't call method "req" without a package or object reference
17:01 Grinnz ?
17:01 sirhalos That's now referring to my $mime        = $pdf->req->headers->content_type();
17:01 Grinnz oh yes, you have to change that because you're not using an upload object anymore
17:01 sirhalos oh okay I see sorry
17:03 [vlad] how do i render a Mojo::Message::Response atm i have to render the ->body part of it
17:03 [vlad] is there any way i can tell mojo just render this without calling ->body?
17:05 sirhalos okay now I have the problem with move_to, it was $pdf->move_to($path); but that no loner works, so I'm assuming I need to change that to $self->move_to($path); but that doesn't work either. Can't locate object method 'move_to'
17:05 Grinnz yes, ->move_to only works for upload objects
17:05 Grinnz you'll have to create the file yourself
17:06 Grinnz https://metacpan.org/pod/Mojo::File is helpful for that
17:07 sirhalos Thank you I'll try that and check back.
17:07 Grinnz use Mojo::File 'path'; path($path)->spurt($data);
17:17 maschine joined #mojo
17:23 dod joined #mojo
17:24 Grinnz jberger: https://xkcd.com/1862/
17:40 sh14 joined #mojo
17:40 jberger boy does it have string type misunderstood
18:03 zivester joined #mojo
18:04 Grinnz it's just a theory!
18:07 * jabberwok proclaims Gravity is only a theory! whilst falling upstairs
18:11 [vlad] according to quantum theory there is a small possibility that you will fal upstairs
18:14 jabberwok hmm.. why do I imagine an abstract painting, The Eleven Dimensions of Unicode?
18:16 Grinnz painted only using emojis
18:17 jabberwok someone needs to (fish) (smack) (group of persons) who (inventor) (emoji which means 'emoji')
18:34 simbabque joined #mojo
18:40 Pierre joined #mojo
19:05 Pyritic joined #mojo
19:30 Pyritic joined #mojo
19:35 simbabque joined #mojo
19:35 simbabque is there always just one instance of a mojo controller or will it be recreated for every request?
19:36 simbabque and as a follow-up, can I put stuff into an attribute that I created in the controller with `has` so that it will be shared for all requests?
19:36 simbabque that's what I would do in catalyst, but maybe there's a more mojo-esque way to do that?
19:40 Grinnz I don't think there's any guarantee as to whether there will be one or multiple instances of a controller; regardless any multi process deployment will break that paradigm
19:41 Grinnz it's better to use an external mechanism to store or share data like a database, redis, Mercury, etc
19:50 pink_mist I thought a controller was created for each request
19:59 jberger pink_mist is correct, one controller per request
19:59 jberger so yes you can use a controller attribute if you want
19:59 jberger oh, but it won't be shared
19:59 jberger sorry I misread
20:00 jberger it is only available in THAT request
20:00 jberger which is no better than the stash
20:08 Grinnz per-request data is best in the stash, per-process data usually as state variables in helpers so sort-of app scoped that way
20:08 Grinnz but shared among the whole app your only real choice is external
20:33 simbabque ok, thanks Grinnz
20:33 simbabque I'm used to thinking in Catalyst, where this is pretty common
20:33 simbabque juggling three web frameworks at the same time is challenging sometimes :)
20:34 Grinnz "this is your brain on Mojo"
21:03 petru joined #mojo
21:44 rshadow joined #mojo
22:31 sri i really wanted to like vscode, but there's just too much that annoys me
22:52 kgoess is there anything obviously wrong with this diff for UserAgent->start? the code is already using $self->ioloop four lines below that anyway:
22:52 kgoess https://gist.github.com/kgoess/49fc4e8ad6eab84687f7d2d8a218e4d0
22:52 Grinnz kgoess: that would be broken
22:52 Grinnz the singleton is used for non-blocking requests on purpose
22:53 Grinnz blocking requests using an inner ioloop is actually the odd part of that code (also on purpose)
22:54 kgoess we have the use case that we want to provide our own ioloop, as well as a callback
22:54 Grinnz sounds like you are using it wrong then
22:54 kgoess arguably, yes, but we are working with a large legacy codebase
22:54 Grinnz there should only ever be one main loop, and non-blocking requests must defer to the main loop
22:55 kgoess yes, I understand, ideally that should be the case
22:55 Grinnz not just ideally, that is the only way things can work
22:56 kgoess all right, here's the story:
22:56 kgoess we have a large, old mod_perl application
22:56 kgoess it has libraries
22:56 kgoess those libraries have libraries
22:56 kgoess down at the end of the call stack, some of the newer libraries use the Mojo::UserAgent to get parallelization
22:56 Grinnz mod_perl won't run a main loop, so non blocking code won't work there
22:56 kgoess the middle libraries are not callback-aware
22:57 kgoess this much is all running fine now
22:57 kgoess we're adding a mojo endpoint
22:57 kgoess which wants to use the same call stack
22:57 kgoess making the entire stack callback aware all the way down to those newer libraries would be problematic
22:58 Grinnz you would have to run the main loop manually inside your code
22:58 kgoess solution: give those newer libraries their own ioloop, the top-level mojo will block until those lower-level ioloop requests complete
22:58 kgoess which is not the most optimal solution for request speed
22:59 kgoess as each request will hang the whole mojo worker
22:59 kgoess but it does actually *work*
22:59 Grinnz there's no way to not hang the worker when mod_perl is running your code
22:59 Grinnz at least, without forking
23:00 kgoess that part is already working just fine, been in production for months
23:00 zerah joined #mojo
23:02 kgoess it starts up Mojo::IOLoop and goes until
23:02 kgoess $event->{'delay'}->wait() while $event->{'delay'}->{'pending'};
23:03 Grinnz pending is an internal implementation detail, not a good idea to rely on that
23:03 Grinnz also ->wait should be sufficient on its own
23:11 kgoess thanks, noted
23:18 kgoess the ioloop accessor in there, that's defaulting to the singleton? or no?
23:18 kgoess has ioloop             => sub { Mojo::IOLoop->new };
23:18 Grinnz no, ->new creates a separate ioloop
23:18 kgoess oic, my diff is wrong then, yes
23:19 Grinnz for what you propose, the correct solution would be a nb_ioloop attribute which defaults to the singleton but could be changed
23:19 Grinnz but i'm not sure if that's the correct solution to your problem
23:20 kgoess ah, yes
23:21 Grinnz i think what you're trying to do is essentially, blocking requests but allowing them to be non-blocking with respect to other requests happening at the same time
23:22 Grinnz which normally you'd use a delay to group them up, but that still doesn't let you use a non-singleton inner ioloop
23:22 kgoess yes, exactly

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