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

IRC log for #mojo, 2015-11-25

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

All times shown according to UTC.

Time Nick Message
00:15 tencendur joined #mojo
00:23 Zoffix joined #mojo
00:39 sri btw. this is the open DBD::Pg issue https://rt.cpan.org/Public/Bug/Display.html?id=93266
00:39 Zoffix left #mojo
00:40 voldemortensen joined #mojo
01:00 cpan_mojo Mojo-Pg-2.16 by SRI https://metacpan.org/release/SRI/Mojo-Pg-2.16
01:26 woz joined #mojo
01:46 marty joined #mojo
01:48 kyshtynbai joined #mojo
01:56 woz joined #mojo
02:37 kaare joined #mojo
02:48 cpan_mojo Mojo-Webqq-1.6.2 by SJDY https://metacpan.org/release/SJDY/Mojo-Webqq-1.6.2
02:58 woz joined #mojo
03:04 mib_59nyoe joined #mojo
03:18 noganex_ joined #mojo
03:26 woz joined #mojo
03:54 Eric1 joined #mojo
04:24 genio almost done with Jessica Jones
04:27 woz joined #mojo
04:49 voldemortensen joined #mojo
05:12 woz joined #mojo
05:45 batman jberger: i haven't released this yet: https://github.com/jhthorsen/mojo-snmp/issues/8
05:45 batman Need to fix an "order" issue first.
05:48 melo joined #mojo
05:56 Adura joined #mojo
06:14 woz joined #mojo
06:17 woz joined #mojo
06:19 woz joined #mojo
06:29 woz joined #mojo
06:56 dod joined #mojo
07:02 dod joined #mojo
07:14 cpan_mojo Mojolicious-Command-donuts-0.04 by CURTIS https://metacpan.org/release/CURTIS/Mojolicious-Command-donuts-0.04
07:40 n16gel joined #mojo
07:47 woz joined #mojo
08:15 Vandal joined #mojo
08:15 sugar joined #mojo
08:20 meshl joined #mojo
08:21 jnbek joined #mojo
08:23 eseyman joined #mojo
08:27 sri trying to keep $results->array because it's so convenient when you're only dealing with one row
08:27 trone joined #mojo
08:33 AndrewIsh joined #mojo
08:39 melo joined #mojo
08:42 osfabibisi joined #mojo
08:45 kyshtynbai joined #mojo
08:48 woz joined #mojo
08:49 CandyAngel Okay, so I'm pretty tempted to port a script I have to Mojolicious and use it's commands functionality.. in theory, I'd then be able to make a nice webUI for it in case anyone else has to use it..
08:50 CandyAngel So rather than running the script and it doing everything (and pausing when it needs to), I can do like
08:51 CandyAngel ./tasks.pl start (start a new process)
08:51 CandyAngel ./tasks.pl import_A importA.txt (imports a dataset)
08:52 CandyAngel ./tasks.pl list_ids_A (lists IDs needed to generate another export)
08:52 CandyAngel etc.
08:52 melo joined #mojo
08:54 CandyAngel I think that would be nicer, because then I can write commands to inspect them
08:55 CandyAngel So: ./tasks.pl why 612349 (task id) would output a bunch of stuff about that task to show what created it, why it is in that state
08:55 * CandyAngel may be babbling because she's quite excited :P
09:04 melo joined #mojo
09:08 meshl joined #mojo
09:19 punter joined #mojo
09:28 dp_ joined #mojo
09:34 woz joined #mojo
10:12 n16gel joined #mojo
10:14 CandyAngel Hmm.. not sure how to get Mojo to remember which report directory it is affecting
10:35 stephen joined #mojo
10:46 CandyAngel There we go, I moved all the Mojo builtin commands to subcommands.. that was easy :|
10:46 CandyAngel Annnd I learned how to do subcommands at the same time. Very useful :)
11:01 melo joined #mojo
11:04 sue joined #mojo
11:16 mtths joined #mojo
11:43 mitya joined #mojo
12:02 woz joined #mojo
12:14 neilhwatson joined #mojo
12:33 berov joined #mojo
12:44 woz joined #mojo
12:47 kes joined #mojo
12:49 woz joined #mojo
13:07 n16gel joined #mojo
13:17 dp_ joined #mojo
13:34 hernan605 joined #mojo
13:40 vanHoesel1 joined #mojo
13:41 marty joined #mojo
13:46 woz joined #mojo
13:52 jberger CandyAngel: fun isn't it :D
13:52 jberger I'm a subcommands addict
13:53 CandyAngel Yeah, learning how to do new things is :) I get perfectionist paralysis a lot and it sucks -.-
13:53 jberger batman: no worries, we are using v2c anyway
13:53 CandyAngel I have it right now in regards to that script :P
13:54 CandyAngel There's like.. three ways i can do it and I don't know which one is "best"
13:54 jberger Implement them all!
13:55 CandyAngel I don't think that would work :P
13:55 CandyAngel The way it currently works, is almost entirely plugin based, with dependencies and such
13:55 jberger MOAR IMPLEMENTATIONS !!!!
13:55 CandyAngel If I redo it with Mojo at its core, I can either just have "./app.pl generate" and it works the same way (with plugins)
13:56 CandyAngel ./app.pl add export1.txt
13:56 CandyAngel (for all exports) and gradually build up the database
13:56 CandyAngel But then you might do it in the wrong order or something.. bleh
13:57 CandyAngel It constantly has to go back to the user because it parses export1.txt, and then gives you a list of things from that export that you have to put into another system to get the export from that..
13:59 jberger CandyAngel: sounds like perhaps the script isn't the real problem ;p
13:59 CandyAngel The systems I have to deal with are? :P
14:00 * jberger hands CandyAngel a morning alcoholic beverage
14:00 CandyAngel Lack of alcohol is the problem? (and thankies, but I don't drink)
14:01 jberger Luckily internet alcohol push-service doesn't work yet either
14:02 jberger (It's my beer!)
14:02 CandyAngel :P
14:02 marcusr almost beer'o'clock in Oslo.
14:02 nic yeah, I just get a 501
14:02 jberger marcusr oh, do you still have that custom Twitter search?
14:03 * jberger pushes nic and marcusr beers
14:03 nic yay, 200
14:04 marcusr jberger: no, I think I broke it. (you mean the one that filters out the irrelevant ones?
14:05 jberger Yeah
14:05 jberger Not so much to use it as to remember the irrelevant ones :p
14:06 * jberger was just reminded of http://mojoupgrade.com/
14:06 marcusr _mojolicious
14:06 meshl joined #mojo
14:07 marcusr @_mojolicious_ even
14:11 woz joined #mojo
14:12 gryphon joined #mojo
14:14 kaare joined #mojo
14:19 jjohn joined #mojo
14:19 jjohn Greetings.
14:20 CandyAngel Heyas jjohn
14:20 jjohn Mojolicious is pretty darn sweet.
14:21 jjohn Coming from RoR, I was looking for partials in the Mojo view.  I think this is just a render_to_string() call, yes?
14:21 jjohn When I do <%= $self->render_to_string(...) %>, I get a deep recursion error.
14:22 jjohn Of course, $self in the view is probably not the controller object anymore.
14:22 jjohn Am I barking up the wrong tree?
14:22 jjohn Is this a FAQ? URLs welcome.
14:23 CandyAngel I don't use it myself, but I think you can use 'include' to bring in other templates
14:23 CandyAngel http://mojolicio.us/perldoc/Mojolicious/Guides/Rendering#Include-templates
14:23 jjohn Oy, that's too easy.
14:23 bpmedley jjohn : http://mojolicio.us/perldoc/Mojolicious/Guides/Rendering#Rendering-to-strings <-- Perhaps this?
14:23 jjohn Thanks.
14:23 jberger jjohn: you probably want the include helper
14:23 jberger oh, bpmedley got there first
14:23 CandyAngel Not familiar to RoR to know if that is what you want?
14:23 CandyAngel s/to/with/
14:23 jjohn Partials are calls made inside of views to pull in other templates
14:24 jjohn E.G. create/edit forms are often the same and can usually share a partial
14:24 bpmedley jjohn : Hrmm.  What are your arguments for render_to_string?
14:25 woz joined #mojo
14:25 jjohn Yup, include looks like the critter I want. Thanks!
14:25 jberger jjohn: you aren't including the same template that you are currently rendering are you?
14:26 jberger cause that would cause a deep recursion
14:26 jjohn Not intentially. :-D
14:26 jjohn It looks like include is render_to_string under the hood
14:26 jberger it is
14:26 jjohn "Instead of include you could also just call "render_to_string" in Mojolicious::Controller to include one template into another."
14:26 jjohn Amazing I missed that the 9 times I read through that guide. :-/
14:26 jberger the actual difference is how you invoke it
14:27 jberger include as a template function vs render_to_string as a controller method
14:27 jberger which depending on how you do it MIGHT create a new controller
14:27 jberger which MIGHT then fire the on build_tx hooks again
14:28 jjohn include is working a whole lot better.
14:28 jberger which if you are rendering in those might cause deep recursion (yes I've seen that before)
14:28 jjohn jberger, I am in the view.
14:28 jberger jjohn: cool, that's much easier
14:30 jjohn Rails is a pretty good framework.  It gets a lot of architecture right.  However, ruby is no Perl and Rails is getting pretty heavy.
14:31 jjohn mojo is clearly influenced by rails in all the good ways.
14:31 jberger jjohn: certainly sri took cues from rails (though he could speak to that better than I can)
14:31 jjohn It could use a little more magic on the router side, but that's manageable.
14:32 jberger jjohn: plenty of magick is possible, what kinds would you like?
14:32 jjohn It is also great that mojo doesn't worry about models.
14:32 jjohn I like the rails resource("controller") thing.
14:32 jberger this is my most insane mojo router hack: https://metacpan.org/pod/Mojolicious::Plugin::Kavorka
14:32 jjohn This one invocation produces about 7 REST routes
14:33 jberger jjohn: there are a few of those on CPAN
14:33 jjohn Whoa!
14:33 jjohn I suspect there are.
14:33 jberger Mojolicious::Plugin::REST (I think) and others with similar names
14:34 woz_ joined #mojo
14:35 jjohn I also built a before filter that I think works a bit more efficiently than the one in AdvancedMod (https://metacpan.org/pod/Mojolicious::Plugin::AdvancedMod#Mojolicious::Plugin::AdvancedMod::ActionFilter)
14:36 jjohn jberger: yes, that module looks about right for my needs.
14:36 jjohn Thanks
14:37 jjohn Also, this is the first time in, what, 20 years? that I have been on IRC.  I used to hang out in #perl *a lot* in the 90s. :-D
14:41 ajr_ joined #mojo
14:44 jjohn When you take Mojo, jquery, bootstrap, DBIx::Class and carton together, it is simply amazing any dynamic web sites got produced at all in the 90s.
15:08 sh4 joined #mojo
15:20 woz joined #mojo
15:20 woz joined #mojo
15:29 asarch joined #mojo
15:44 woz joined #mojo
15:47 woz joined #mojo
15:48 ashimema Just been asked by colleague to help him work through some erratic auth behaviour but I'm getting confused by his super simple code..
15:49 ashimema Just been asked by colleague to help him work through some erratic auth behaviour but I'm getting confused by his super simple code..
15:49 ashimema https://ssl.thorsen.pm/paste/eb830bc9bbcd
15:49 jberger ashimema: that's just HTTP basic auth
15:49 ashimema I'm not seeing any session creation anywhere.. so am I right in thinking anything 'under' the under expects a username and password sent in with every request right?
15:50 ashimema yup.. basic auth only.. 'tis only meant to be simple ;)
15:50 voldemortensen joined #mojo
15:50 jberger no, it gets merged into the absolute url
15:50 ashimema but each subsequent request still needs the username and password right.. else they should fail
15:50 jberger scheme://user:pass@host/path
15:50 Grinnz yes, that's how browsers implement basic auth
15:51 ashimema so the browser stores it and sends it with each request..
15:51 Grinnz yep
15:51 ashimema I didn't realise that.. thanks
15:51 jberger oh, yeah, browsers resend all the time
15:51 jberger kinda annoying actually
15:51 Grinnz which is also why basic auth is impossible to do anything useful with
15:51 ashimema I thought you needed a session (i.e. cookie) to store it
15:51 Grinnz like log out
15:51 jberger its actually kinda hard to implement a log out
15:51 ashimema oh i see..
15:51 ashimema that rings a bell now!
15:51 ashimema thanks guys..
15:52 ashimema must be something else that's booting users out then
15:52 ashimema or rather, re-requesting the login
15:52 jberger also means you are reprocessing that every time
15:52 ashimema indeed..
15:52 jberger session is much cheaper
15:52 ashimema I can't say I like it much..
15:53 ashimema might throw together a tiny bit of session handling for him.. Mojo Sessions make it so easy ;)
15:53 ashimema thanks guys
15:53 jberger you can implement session based auth with basic as a fallback (only evaluated if no user in the session)
15:53 jberger but you still have the log out problem
15:53 jberger it IS really handy for development though, because its easy to auth in a single request at the command line
15:56 woz joined #mojo
15:56 Grinnz https://i.imgur.com/DLmiCXj.jpg CSS problems
15:57 woz joined #mojo
15:57 ashimema :)
15:57 ashimema cheers chaps
15:59 ashimema so.. does a basic auth ever expire at all in any way..
16:00 ashimema seems he's finding that after a while he's greated seemingly at random with a login prompt again
16:00 bpmedley ashimema : I believe expiring a basic auth is totally client dependent and even varies per version of the client.
16:01 ashimema he's even seeminlgy finding that re-enterting the login details that fails on the subsequent request too
16:01 ashimema how odd
16:02 ashimema hmm..
16:06 ashimema ooh.. there's some funky use of 'under' here..  can you nest unders?
16:06 ashimema i.e
16:07 jberger yes
16:07 jberger just be sure you understand what they are doing (and how they might interact)
16:07 ashimema https://ssl.thorsen.pm/paste/318096838c0e
16:08 ashimema so the first under will trigger the auth.. on all routes beneath it.. right..
16:08 jberger yes, those would both get called
16:08 ashimema I'm not using under personally.
16:08 ashimema ok..
16:08 jberger if you matched both routes
16:08 ashimema so /:inst/:thing
16:08 woz joined #mojo
16:08 jberger /myplace/mything would go through both unders
16:08 ashimema would match the first under, then the second under
16:09 ashimema but / would match neither right..
16:09 jberger correct
16:09 ashimema even though it's positioned underneath the first under
16:09 ashimema ok.. I see the logic there.
16:09 jberger oh, no
16:09 jberger sorry, this is the lite router
16:09 ashimema yes..
16:09 jberger you have no / handler at all then
16:09 ashimema there is one above that under too
16:10 jberger the get / is actually get /:place with the under
16:10 jberger I always use the full router
16:10 ashimema me too ;)
16:10 ashimema lite apps now confuse me since I switch to full fat mojo ;)
16:11 ashimema So..
16:11 ashimema that code could also be written as:
16:11 jberger the only difference is this thing, the global mutable router (which makes the DSL syntax possible)
16:11 ashimema https://ssl.thorsen.pm/paste/373ece500099
16:11 ashimema and mean exactly the same thing?
16:12 jberger ashimema: no
16:12 ashimema ah.. ok
16:12 jberger that get would match /:inst/:inst
16:12 * ashimema is lost again
16:12 jberger its a nested tree structure
16:12 ashimema so does that mean his nested under matches /:inst/:inst/:thing
16:12 ashimema bit /:inst/:thing
16:13 jberger hmmmm, yes it does
16:13 jberger in lite, you can use group { ... } to contain the router mutation
16:14 jberger or just do my $r = app->routes; and then setup the router as if it were a full app
16:14 jberger which is what I do
16:14 jberger when I use lite
16:20 lluad joined #mojo
16:22 woz joined #mojo
16:40 woz joined #mojo
16:45 woz joined #mojo
16:51 dod joined #mojo
16:57 dod joined #mojo
16:58 dod joined #mojo
16:58 woz joined #mojo
17:00 jjohn left #mojo
17:13 vytas joined #mojo
17:15 ZoffixW joined #mojo
17:23 jberger DIE IE DIE!!! https://www.microsoft.com/en-us/WindowsForBusiness/End-of-IE-support
17:27 GabrielVieira joined #mojo
17:30 Grinnz_ \o/
17:33 PryMar56 joined #mojo
17:38 batman jberger: Nice! Let me know it something isn't very intuitive/working as expected :) (SNMP)
17:38 jberger batman: one thing is that get_table isn't implemented
17:39 jberger I can probably wrap it with the add_custom thingy, but I have to learn what I'm doing first :-P
17:40 vanHoesel joined #mojo
17:43 batman jberger: hehe. Yeah. I've never understood what's nice about get_table. That's why I haven't implemented it.
17:43 batman There are already two custom methods in the source code. Maybe they can help you out.
17:43 jberger I don't know either, but the old script I'm porting uses it
17:44 jberger I'm hoping that the way it was used that walk will be sufficient
17:44 batman Aha. What I found is that get_table didn't really help me and it was slow...
17:44 batman But I don't have any more details, since it's been almost ten years since I worked with SNMP :/
17:45 batman walk/bulk_walk is often what you want instead, yes :)
17:47 batman jberger: would appreciate if you pointed jjohn to #swagger when he asked about REST API :/
17:48 * jberger still needs to learn more about swagger
17:48 jberger does it actually generate the routes or just document them?
17:48 kyshtynbai o/ I've got a more generic than specific question. According to MVC concept good practice of coding, where should I put my sql querries: in Model class of in Controller class?
17:48 jberger (document and validate)
17:48 batman jberger: join #swagger and I'll tell more :)
17:49 jberger on freenode or perl?
17:49 batman kyshtynbai: in your models.
17:49 preaction kyshtynbai: the model class should encapsulate all the business logic and database-specific mumbo-jumbo
17:49 kyshtynbai tnx
17:49 batman jberger: perl
17:58 asarch I have: my $content = "<h1>Programming Web Apps With Mojolicious</h1><h2>Chapter 1 - Fun!</h2><p>This manual...</p>"; and I would like to escape the content: <p><%= $content %></p>
17:58 asarch Is there any way to do $content =~ s/\n/<br \/>/g; to the escaped content?
17:59 asarch Is valid: my $escaped = <%= $content %>; ?
18:03 tencendur joined #mojo
18:06 preaction asarch: % my $escaped = $content; # then you can do <%= $escaped %>
18:06 preaction but really you should do this somewhere else
18:06 preaction or use markdown instead perhaps
18:07 asarch Thank you
18:07 asarch Thank you very much preaction
18:07 woz joined #mojo
18:17 asarch One stupid question: If my server is RESTful and /students/ gives something like: {"count" : 2, "results" : {{"firstname" : "John", "lastname" : "Doe"}, {"firstname":... }}, I need an extra part to "transform" JSON into html: <table>...</table>, right?
18:17 asarch So you can easily check the list of all students?
18:18 batman asarch: maybe you want jberger'so table plugin?
18:18 batman http://search.cpan.org/~jberger/Mojolicious-Plugin-ReplyTable-0.04/lib/Mojolicious/Plugin/ReplyTable.pm
18:19 * batman hates that search.cpan.org comes up first in Google search :(
18:19 asarch How can the controller would know when to dispatch JSON and when HTML?
18:19 batman asarch: /students.json /students.html
18:20 asarch Obviously!
18:20 batman Or .csv or .xslt :)
18:20 batman You can also do it with a HTTP header, but that's not very browser friendly.
18:20 asarch Or even .xml
18:21 batman Yeah... I wouldn't do xml, unless someone required me to do so...
18:21 batman :)
18:22 * asarch takes notes...
18:22 batman But in theory: you could even do .mp3 with a speech synthesizer ;)
18:23 batman asarch: https://metacpan.org/pod/Mojolicious::Controller#respond_to
18:24 * Grinnz_ has a bot command that does that via microsoft's speak API..
18:25 Grinnz_ https://msdn.microsoft.com/en-us/library/ff512420.aspx
18:36 jberger batman: omg a speech synthesizer would be an awesome plugin
18:37 Grinnz_ unless someone's written a PP one you'd need to require festival libs or something
18:38 asarch What module do you use to encode/decode JSON?
18:38 Grinnz_ Mojo::JSON, and there's built in JSON handlers for rendering
18:38 batman jberger: haha!
18:39 * batman won't write that.
18:39 Grinnz_ https://metacpan.org/pod/Mojolicious::Guides::Rendering#Rendering-JSON
18:39 * jberger notes for April fool's day
18:39 Grinnz_ https://metacpan.org/pod/Mojolicious::Guides::Cookbook#JSON-web-services
18:39 * batman 's plane takes off soon.
18:40 batman http://vignette3.wikia.nocookie.net/marvel_dc/images/4/4f/Batplane_2.jpg/revision/latest?cb=20070122182925
18:40 batman bbl
18:49 asarch Thank you!
18:49 asarch Thank you very much :-)
18:49 jberger batman: where are you going?
19:06 woz joined #mojo
19:08 trone joined #mojo
19:36 GabrielVieira joined #mojo
19:39 ajr_ joined #mojo
19:41 sugar joined #mojo
19:51 woz joined #mojo
20:03 woz joined #mojo
20:14 woz joined #mojo
20:16 melo joined #mojo
20:19 batman jberger: home :)
20:20 jberger ah, then I've asked the wrong question
20:20 jberger batman: where've you been?
20:21 batman ...and I'm being difficult :/
20:22 batman Been three days in Tromsø (north in Norway)
20:22 woz joined #mojo
20:23 jberger oh cool (I mean, probably reaaaallly coool (cold)
20:23 jberger )
20:23 jberger any aurora?
20:23 batman Too many clouds :/
20:23 batman Better luck next time!
20:24 jberger too bad
20:25 batman Well. Good excuse to go back, hehe
20:26 batman Oslo is just as cold.
20:26 jberger yeah
20:26 tyldum Oslo is colder on the cold days, sure
20:29 batman Not sure if any of the cities facing the golf stream gets cold..?
20:29 batman s/cities/places/
20:29 tyldum s/golf/gulf/
20:29 tyldum ;)
20:30 batman Crap. Can't even blame autocorrect for that one, hehe
20:30 batman brain--
20:31 tyldum The same latitude in Alaska is gruesome, while Tromsø is barely below a few minus on average in the winter.
20:33 jberger tyldum: that's interesting, and yeah, I'd base my assumption on an alaska analogy
20:34 jberger tyldum: http://www.sciencedaily.com/releases/2011/12/111202091148.htm
20:39 tyldum Yeah. Notice how it even reachen up to 78 deg north. Spitsbergen/Svalbard
20:40 * sri changes title to "the weather channel"
20:41 tyldum I'm sure Mojo::Weather exists
20:42 Grinnz_ well, something like that is planned ;)
20:43 * Grinnz_ was planning on making a Mojo::WebService::Wunderground next
20:43 batman sri: haha
20:43 batman tyldum: me and marcus made Mojo::Yr :)
20:44 sugar joined #mojo
20:44 jberger Grinnz_++
20:44 batman https://metacpan.org/pod/Mojo::YR <-- best weather channel there is :)
20:44 tyldum Grinnz_: You just need to make the Swagger2 spec for it!
20:45 batman YR = norwegian weather service. ranked as one of the best in the world actually.
20:45 Grinnz_ cool
20:46 melo joined #mojo
20:46 hahainternet joined #mojo
20:48 meshl joined #mojo
20:53 Quai Yr not YR :P "Yr" is the norwegian word for drizzle, not a abbreviation
20:54 batman Quai: not sure if we will rename the module...
20:55 sugar joined #mojo
20:58 marcusr pretty sure we won't
21:00 jberger Yeah, Right
21:01 Quai :P
21:01 Quai you can call it a abbreviation for "Yr Rocks!" or something.
21:03 woz joined #mojo
21:05 batman Quai: haha! I like it ;)
21:05 batman marcusr++
21:10 marcusr batman: last last week tonight of the year this week. Going to be rough :)
21:10 jberger marcusr: yeah, off until valentine's day! what is this crap?!
21:11 marcusr jberger: apparently they pay him too well.
21:11 Grinnz_ marcusr: that was an interesting sentence to parse
21:11 marcusr Grinnz_: I guess I could have used capitalization better.
21:15 tyldum marcusr: You know you have succeeded when the big debate is the name of the bastard^Wmodule
21:23 n16gel joined #mojo
21:23 batman marcusr: yeah. This is a rough time to go through...
21:24 batman But I think we will manage :)
21:24 batman ...barely
21:43 berov1 joined #mojo
21:43 berov1 Hi, I have the following question
21:45 berov1 I want to make a call to a database (using Mojo::mysql) and retreave some value which to use as a custom header
21:46 berov1 How can I do the db query not blocking(I know how) so the mojo request loop waits till the value is reetreived from the database
21:47 berov1 I mean the response is not sent while the value from the database is being retreived
21:47 genio You can use the delay helper in your controller method.  Can you paste what you're trying so we can provide better help than that?
21:47 punter joined #mojo
21:48 berov1 Ioh I am using the $c->delay
21:48 Grinnz The delay helper will automatically set render_later for you and keep the transaction around so you can render in the last step
21:48 berov1 the problem is that the response is sent before I have the value
21:48 genio can you paste your controller method?
21:48 berov1 I am trying to do this in after_dispatch
21:49 Grinnz ...oh
21:49 berov1 because I want to add the header transparantly for the current action
21:49 Grinnz you can't have non-blocking callbacks in hooks
21:49 berov1 huh
21:50 berov1 I can but the hooks are not being wait for
21:50 Grinnz think about it; you might have a page that has already rendered by the time it even gets to after_dispatch
21:50 berov1 how can I synchronise
21:50 berov1 Grinnz: exactly this is happenning :)
21:52 Grinnz you can put an "under" above all the routes which does the asynchronous call and then continues the dispatch chain
21:52 Grinnz https://metacpan.org/pod/Mojolicious::Guides::Routing#Under
21:52 berov1 Iany idea to not to have to do my async call to the database in the action
21:52 Grinnz once the asynchronous call has completed
21:54 Grinnz the only way to know that the async call will be done before the page is rendered is to wait for it before even calling the action method
21:56 berov1 Grinnz: but will this block? I want to be able to handle let say 5 requests within one process
21:56 berov1 ?
21:56 Zoffix joined #mojo
21:57 Grinnz berov1, it won't block the worker, but it will hold up the request dispatch
21:57 Grinnz for that one request
21:57 Grinnz berov1, see the part about "continue" in that link
21:58 Grinnz you have the "under" action return false, so that it does not continue, and then have the callback call "continue" once you get the response from the DB
21:58 Zoffix left #mojo
21:59 berov1 Grinnz: I was looking at it, thanks, will try to understand it. It is fine to hold up the request dispatch...
21:59 berov1 let me try...
22:02 batman berov1: you can do delayed in "around" hooks
22:02 GabrielVieira joined #mojo
22:02 berov1 around-action ?
22:02 berov1 :D an example ?
22:03 batman Yes. Just call $next->() from the last step in the delay
22:03 batman https://metacpan.org/pod/Mojolicious#around_action
22:03 PopeF joined #mojo
22:04 batman But once you call next, you can't delay after
22:04 berov1 batman: I want exactly this. not... I want to do somethhing after the action finishes its work
22:04 woz joined #mojo
22:04 batman If that makes sense...
22:04 batman Ah. Sorry. Ignore me then.
22:04 berov1 uh I want after $next
22:04 Grinnz berov1, doing something after the action will never work
22:04 meshl joined #mojo
22:05 Grinnz berov1, because you cannot know when the action will render
22:05 batman berov1: maybe we can help better if we understand what you want to do in more detail...
22:05 berov1 Grinnz: but imagine that the action prepares the content, some things I want to log in the database
22:05 Grinnz berov1, the action does not prepare the content, it renders the content
22:06 berov1 In the action I have other calls to the database
22:06 Grinnz berov1, you can do things after the action if they don't affect the render, sure
22:06 batman berov1: if you want to log, you can do that from $tx->on(finish...)
22:07 Grinnz berov1, but for what you wanted to include as a header, you have to have that ready before the action
22:08 berov1 the (my) action prepares an ETag, which I want to store in the database
22:08 berov1 but then I want to add a custom header X-RequestID which I can retreive after I store the ETag
22:09 berov1 may be my design is bad
22:09 Grinnz then you will need to make all your actions call an asynchronous function with their content, and only in the callback of *that* can you render in each action
22:10 Grinnz so each action will need to use the delay helper to call that
22:10 Grinnz then render
22:11 berov1 batman: I am using Swagger2
22:11 punter joined #mojo
22:14 berov1 uh I even have cases when I use cache from a redis db and just add the cached content $res->body($json) and then $c->rendered(200)
22:14 Grinnz you can't set a header after you render, and an action will not wait for a non-blocking call unless you tell it to, so the setup you propose can only be done that way, i'm not sure if there might be a better design
22:15 * berov1 looking at $tx->on(finish...)
23:39 CandyAngel What's the opinion on having modules released on CPAN that use Mojo modules but aren't really about Mojolicious?
23:40 preaction what about it?
23:41 CandyAngel Just wondering if it was frowned upon, not recommended, welcomed etc.
23:41 Adura It shouldn't matter.
23:41 CandyAngel I keep thinking about reimplementing Module::Pluggable using Mojo::loader
23:41 preaction https://metacpan.org/requires/distribution/Mojolicious?sort=[[2,1]] <- here's all the things that depend on mojolicious. not all of them are about mojolicious, or even about web applications
23:42 CandyAngel Especially Module::Pluggable::Dependency because it has an annoying bug :P
23:45 preaction did you report the bug? perhaps patch to fix the bug?
23:47 CandyAngel Hm, I have a local patch and I thought it had been reported already but there's no bug report on CPAN for it
23:47 PryMar56 joined #mojo
23:48 CandyAngel Basically, if no plugins are found, you get a warning because it expects and arrayref or something
23:48 CandyAngel expects an arrayref*

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