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

IRC log for #mojo, 2018-01-09

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

All times shown according to UTC.

Time Nick Message
00:00 djk joined #mojo
00:07 kgoess joined #mojo
00:09 gizmomathboy joined #mojo
02:03 FROGGS_ joined #mojo
02:22 Afristar_ joined #mojo
02:22 noganex joined #mojo
03:11 Leffe joined #mojo
03:14 Ya_ALLAH_Ya_Muhmd joined #mojo
03:14 Ya_ALLAH_Ya_Muhmd left #mojo
04:36 inokenty-w joined #mojo
05:02 wilma joined #mojo
05:03 wilma hi
05:04 dboehmer_ joined #mojo
05:13 Kharec joined #mojo
05:19 Leffe joined #mojo
06:25 FROGGS_ sri: Thank you!
06:41 dod joined #mojo
06:49 dod joined #mojo
06:50 gordonfish joined #mojo
07:14 Leffe joined #mojo
07:32 dod joined #mojo
07:51 dod joined #mojo
07:58 McA joined #mojo
08:23 rcz I'm extending an old system. I need to do some authentication that checks a cookie first, then a file, then if the user doesn't exist here, check through LDAP, and if it's there, add it to the file, return 1. This seems a bit heavy to just have in my controller subroutine, so I want some abstration. What'd be a good way to achieve this? A simple Perl module?
08:23 rcz A Mojo plugin? Helpers seem unnecessary
08:29 dod joined #mojo
08:31 Leffe joined #mojo
08:32 kes joined #mojo
08:32 trone joined #mojo
09:00 rcz Why can I use my registered helper in templates but not in my controller?
09:26 Vandal joined #mojo
10:18 rcz Can someone please help me out with plugins? :)
10:49 karjala_ joined #mojo
11:05 tchaves joined #mojo
11:28 mishanti1 rcz: Helpers should be available in your controllers. `$c->do_the_thing()` where $c is teh controller object (first parameter to the action-method) and 'do_the_thing()' being the helper you registered.
11:29 exp-innit I'm implementing an /errors endpoint for receiving front-end errors and logging them
11:29 exp-innit I'm sending through all the variables from the front as form parameters, this is all fine
11:29 exp-innit but i'd also like to dump any information available about the client on the server side
11:29 exp-innit is there a preferred mechanism for this?
11:45 mishanti1 exp-innit: I've always just data-dumped / printed the request-object (`$c->req()`) and all children and from there picket what I wanted to log.
11:45 mishanti1 There might be a better / standard way of slurping that stuff, but I don't know of it, so I just fiddle around with ->req().
11:46 exp-innit mishanti1: yeah i'm just printing req headers, env, and body params
12:09 rcz mishanti1: Thank you, I figured it out that far.
12:10 rcz I'm having some architectural difficulties. I want to make a Perl module (package?) to handle some authentication, but I'm not sure where I should put it and how I should load it (use it in controllers).
12:12 mib_m6esyj joined #mojo
12:15 dod joined #mojo
12:15 rcz I really want to have it seperate from the Mojo app so it can be reused in other applications, and maybe load it into Mojo as a plugin? I'm clueless
12:23 karjala_ rcz here's what I do
12:23 karjala_ I created a mojolicious plugin in the Plugin(s) subdirectory
12:23 karjala_ which creates a user_id helper
12:24 rcz so in lib/MyApp/Plugin/Foo.pm?
12:24 karjala_ Yes
12:24 karjala_ Auth.pm for example
12:24 karjala_ so I do this:
12:24 karjala_ $c->user_id(15) to let mojolicious create a cookie and send it to the user's browser
12:24 karjala_ and $c->user_id to decode the user's cookie and return the user_id
12:25 karjala_ so in the beginning of every route handler (endpoint), I write: my $user_id = $c->user_id or not_authenticated
12:25 rcz That doesn't seem very scalable
12:25 karjala_ why not?
12:26 karjala_ It has served me well
12:26 rcz You mean in every controller subroutine that's supposed to render html?
12:26 karjala_ not_authenticated is a custom function that raises an exception (that gets caught and sends error 401)
12:27 karjala_ yes, I add this one line in every controller subroutine that needs to know what the user id is
12:27 karjala_ you could ignore it, and just write $c->user_id wherever needed
12:28 karjala_ can't imagine how it could be any better than this
12:28 rcz alright.. I'm with you so far. But I need some abstraction, since the authentication is pretty stupid (complicated), and I want this to be done in a Perl module that can also be shared with other Perl apps (not Mojo).
12:29 rcz And then maybe loaded into Mojo as a plugin
12:29 exp-innit rcz: write a plugin that wraps your perl module
12:29 karjala_ yes
12:29 rcz ^ not sure about this part, since mostly this is an architectural problem for me
12:29 rcz Yes but how? Mostly I'm just confused about where to put things and how to load them
12:29 karjala_ a plugin that uses your perl module, is what I'd do
12:30 djk joined #mojo
12:30 karjala_ do you know 'use lib'?
12:30 rcz No
12:30 exp-innit rcz: is this a mojo lite app, or a full app?
12:30 rcz Full app
12:31 exp-innit then you should already have a lib directory
12:31 rcz Yes
12:31 exp-innit perl modules may live there, or wherever else your system specifies
12:31 rcz Alright.. I guess I'm just confusing myself with this whole tmtowtdi philosophy
12:32 rcz I mean I wouldn't be using perl for this if I had a choice :p
12:33 karjala_ Perl is an excellent choice
12:34 karjala_ You can either place your new module in a different directory, anywhere in the filesystem, and write: use lib '/the/path/to/that/directory'; in one of the perl files
12:34 karjala_ or you can place your new module under MyApp/lib
12:34 karjala_ that
12:34 exp-innit rcz: you should find Perl missing almost nothing
12:35 rcz karjala_: if I choose to have it in my app's lib/, I would have to name it accordingly though
12:35 rcz I love it for small applications and scripting, but adding a bit of complexity or even OO seems ridiculous in most cases, compared to other tools
12:35 rcz Mojo makes it a breeze so far though
12:35 exp-innit rcz: 'lib' doesn't have a prefix
12:35 exp-innit you may name it as you see fit
12:36 exp-innit Your/Module.pm will be loaded with `use Your::Module`
12:36 exp-innit lunch for me
12:36 rcz exp-innit: I realize that, but it would still have to call it 'package MyApp::Module' and not just 'package Module'?
12:37 karjala_ no it wouldn't
12:37 karjala_ if it's in MyApp/lib/Module.pm, then you use it with: use Module;
12:37 karjala_ and write package Module on top
12:37 rcz oh right
12:38 karjala_ or myapp/lib/Module.pm (i don't remember the casing of myapp)
12:38 karjala_ there's a lib directory in my_app or whatever it's called
12:38 sri naming of the project dir changed over time
12:41 AndrewIsh joined #mojo
13:04 rcz Thanks for the help karjala_ exp-innit
13:04 karjala_ did you solve your problem?
13:04 karjala_ welcome
13:15 rcz karjala_ not yet, I need to work a bit on it, but I get the idea :)
13:19 Kharec joined #mojo
13:38 marty joined #mojo
13:44 rcz joined #mojo
13:45 McA joined #mojo
13:48 McA joined #mojo
14:06 CHYC joined #mojo
14:08 dod1 joined #mojo
14:53 gryphon joined #mojo
15:18 rick_soc1 joined #mojo
15:21 rick_soc1 good morning
15:21 purl For you maybe.
15:21 CandyAngel Morning rick_soc1
15:24 mib_ivj8z5 joined #mojo
15:34 gizmomathboy joined #mojo
15:36 ChmEarl joined #mojo
16:11 orev1 joined #mojo
16:14 mohawk karjala, isn't that authentication stuff what "under" is for?
16:17 karjala_ Personally, I use 'under' for authorization (like when a set of URLs under the same start-of-path require you to have admin rights)
16:17 karjala_ Some route handlers might not need the user_id - why force all routes to read the DB to detect it?
16:18 exp-innit oh, a question I've had but forgot to mention
16:18 karjala_ and at some point you'll need the id itself... isn't it better to just write $c->user_id to get it, rather than $c->stash('user_id')
16:18 exp-innit I'm trying to ensure our CI reports code coverage
16:18 karjala_ ?
16:18 exp-innit but I notice if I don't `use` each controller that I have, they don't get included in the code coverage
16:18 karjala_ so a helper will be needed, no?
16:18 exp-innit presumably as `prove` or whatever module is responsible can't see their use, is this a problem that's noted?
16:25 jberger exp-innit: it is possible that code that is not exercised at all is excluded from the report, but for details on that better see say #perl-qa or #toolchain
16:25 exp-innit jberger: that is the case, i just wondered if there was a recommended mechanism in mojo to traverse all defined controllers or similar
16:26 exp-innit manually `use`ing them does the job, but requires me to keep track, i could use library find routines / findbin et
16:28 mohawk exp-innit, do you have automated testing for your routes?
16:28 mohawk that seems like it would be the way forward
16:29 jberger they are all used, that's part of the application warm-up process
16:29 jberger at least unless that has changed without my notice
16:30 mohawk karjala, my thinking was you could have >1 "under", eg one that does admin-authentication, one that does user_id that you only apply to some routes...
16:30 exp-innit mohawk: not yet, I need to rework our CI so i can instantiate postgres databases etc
16:30 exp-innit jberger: well they get eliminated from the CI and the app certainly starts up, but mohawk raises a valid point
16:30 exp-innit once i'm actually running tests using them, there'll be no excuse
16:31 mohawk shurely there's module for generating a PG db already
16:32 exp-innit mohawk: not without crapping all over CI pipelines :)
16:32 exp-innit but that's my own problem
16:32 mohawk good luck, sounds like some tricky stuff :-)
16:33 exp-innit i have stored procedures i require to be exercised, so yeah
16:35 jberger so several points
16:35 jberger first, I'm not actually sure that warmup does load the controllers, though I thought it did
16:36 jberger second, certainly you ought to have tests if you expect to have any coverage of them; that said I guess seeing a giant 0 is preferable to not seeing anything
16:36 jberger third, with proper model isolation, you can avoid the db thing by mocking out model methods
16:36 jberger forth, Mojo::Pg makes it fairly easily to isolate tests by using search_path
16:53 exp-innit jberger: stored procedures, so pointless mocking them out, as it doesn't actually test anything
16:53 exp-innit but everything else i don't disagree with you on :)
16:54 exp-innit and yeah, i should have tests of everywhere, no argument can be had
16:54 jberger the perl-side methods that call the stored procedures could still be mocked
16:55 jberger and if you deploy the stored procs via Mojo::Pg::Migrations they can be installed into the isolated schema and tested directly too
16:55 exp-innit i am currently using dbic, and i'm leaving migrations till fairly last
16:55 exp-innit as i've never worked on anything in any language where migrations weren't a pain :)
16:56 exp-innit but again, no arugment, thank you for the information
16:57 jberger yeah, I used DBICDH for Galileo, it wasn't totally easy
16:57 jberger though to be fair, I was trying to make it deploy db-agnostically which it really doesn't want to do
16:58 jberger Mojo::Pg::Migrations has actually really helped me appreciate relational dbs again
16:58 jberger before it I hated migration management so much that I tried to avoid it
16:58 exp-innit if I can use Mojo::Pg with dbic then I will absolutely adopt it
16:58 jberger seriously nice blend of power and simplicity
16:58 marty joined #mojo
16:58 jberger that I'm not sure about
16:59 exp-innit i already have a variety of complex ORM behaviours i can't lose
16:59 jberger can DBIC output its DDL?
16:59 exp-innit (things like automated relationship / m2m handling in searches, autocompletes, that sort of thing)
16:59 exp-innit jberger: yeah afaik it's normal to provision from it
16:59 jberger if so you could just put that into a migrations file
17:00 jberger though I guess that would only work for a full migration not differential between versions
17:00 exp-innit well
17:00 jberger not totally ideal
17:00 exp-innit no reason i couldn't do differences between versions
17:00 exp-innit typically i develop schema first then dbicdump it, i don't deploy from .sql files
17:00 exp-innit mostly because .sql files are only really easy to write if you're doing simple tables etc
17:00 exp-innit but there's nothing wrong with the idea of treating it like a git revision history
17:01 exp-innit jberger: http://search.cpan.org/~ribasushi/DBIx-Class-0.082840/lib/DBIx/Class/Storage/DBI.pm#deployment_statements should fufill your requirements
17:01 jberger exp-innit: https://github.com/kraih/minion/blob/master/lib/Minion/Backend/Pg.pm#L938
17:01 jberger that's the Minion::Backend::Pg schema
17:02 exp-innit i see
17:02 exp-innit yeah while this works as a migration system, it will probably suffer the same issues when used between many people unless they are careful to curate it, unless there's more to it I am unaware of
17:02 exp-innit i'll give it a good solid read though
17:03 jberger exp-innit actually that DBIC thing looks workable too
17:03 jberger do whatever seems best
17:03 exp-innit perhaps, seems a bit over the top
17:03 exp-innit for now anyhow my biggest issue is doing this in CI
17:03 jberger but I highly recommend doing something like one of those, since then you have the schema in git
17:04 jberger and you can programmatically deploy
17:04 exp-innit oh, yes i already have a dumped schema.sql in git, hacky but a good first step
17:04 jberger which lets you test your db behavior
17:04 exp-innit well the problem with testing is that i have jenkins slaves, but none that are properly isolated from each other, and none which are properly ephemeral
17:04 exp-innit so if someone requires 9.4, and someone requires 9.5, we have a problem already
17:04 jberger that's what postgres search path and schema aere about
17:04 jberger oh
17:05 jberger well that's a social problem
17:05 exp-innit it's solvable, the build slaves should just be ephemeral, so mr 9.5 is running in a different container
17:05 exp-innit but it's all time to solve, time that i never have ☺
17:05 exp-innit anyhow as usual a series of excellent answers, and my Mojo is looking nicer than ever
17:06 jberger http://mojolicious.org/perldoc/Mojo/Pg#search_path
17:06 jberger ^^ that's isolation within the same db server
17:06 exp-innit yeah i already have 'old', 'public' and 'audit' :)
17:07 exp-innit <3 postgres schemas
17:07 exp-innit it also has an implicit search that isn't mentioned usually
17:07 jberger right but if you have t_test_path_filename schema, deploy to it, and test there for that one test file
17:07 jberger test isolation
17:08 jberger almost as good as ephemeral db servers
17:08 exp-innit well yeah I could just use `uuidgen` as my schema, but it's a stopgap for sure
17:08 exp-innit I agree with you though
17:08 exp-innit stop being right :)
17:08 jberger hahaha
17:08 jberger ok, I'll let you alone
17:08 exp-innit i'm off home shortly so i will vanish
17:08 sri the blog example actually has test isolation now https://github.com/kraih/mojo-pg/blob/master/examples/blog/t/blog.t
17:08 jberger mostly I want you to be aware of what's possible, and not knowing what you know I'm likely to spew randomly
17:08 exp-innit jberger: much appreciated
17:09 exp-innit also fwiw, there's allegedly a mojo / dbic example on heroku, but it does not work
17:09 exp-innit http://mojoexample.herokuapp.com/
17:09 exp-innit i do not know if this is deprecated or what
17:09 jberger sri: ah, nice, I can use that as an example then too
17:09 jberger exp-innit: probably stuff from tempire
17:09 jberger his stuff was good at the time but is showing signs of age
17:10 jberger and he is rarely around anymore, spending most of his time in iOS land as I understand it
17:10 exp-innit the poor soul
17:10 exp-innit i mention because it is listed as #1 here: https://github.com/kraih/mojo/wiki/Database-support
17:10 exp-innit and should be probably removed in this case
17:10 sri new-ish features like config overrides made testing mojo apps a lot cooler https://github.com/kraih/mojo-pg/blob/master/examples/blog/t/blog.t#L23
17:11 jberger exp-innit: the wiki is public (hint hint)
17:11 exp-innit jberger: would you like the entire section removed? I don't have a relevant dbic example to give
17:11 exp-innit also sri that is quite nice, an oft overlooked feature
17:11 jberger maybe move to the bottom as "Old Examples" or some such
17:14 exp-innit jberger: happy? :)
17:15 jberger sure
17:16 jberger of course it would be great to have a working example with dbic
17:16 jberger perhaps I could put Galileo in there
17:16 jberger but it does suffer from some of the hacks I used for making it db agnostic
17:17 sri i wish we had a guide explaining the blog example in detail
17:18 exp-innit jberger: what I'm working on I'm afraid wouldn't be suitable, if I find time to work on a personal project though ☺
17:21 exp-innit jberger: right i'm off, thank you again for all the help
17:21 exp-innit advice, suggestions, 's all grand :)
17:23 jberger glad to help
17:23 jberger sri: that does sound like a good blog post
17:23 jberger I'll add it to my list
17:24 sri jberger: naah, i think it would be bigger
17:24 jberger blog series? guide?
17:24 sri why not both? :)
17:24 jberger it could be a Guide in Mojo::Pg
17:24 jberger true
17:24 sri honestly, i would consider it for a core guide
17:24 jberger I suppose that's true
17:24 sri it's such common problems
17:24 jberger yeah
17:25 sri so many best practices just one after another
17:25 jberger the dependency issue isn't that bad when it is just examples
17:25 jberger indeed
17:25 marty joined #mojo
17:25 sri Mojo::Pg is a spin-off, so, it wouldn't really be out of place in the core guides
17:26 sri little disclaimer at the start and it's fine imo
17:27 sri it's not like there is much of a chance we'll ever change the recommended database from postgres :)
17:29 jberger right, I wasn't really criticizing that, I was just explaining my initial choice, core is fine by me
17:30 jberger sri: while you're here
17:30 jberger is it a problem that the warmup for the renderer doesn't seem to preload the controller classes
17:30 jberger ?
17:30 jberger it asks for data_sections from those that are loaded it seems
17:31 jberger (that must be for mojolyst right?)
17:31 sri i don't actually know
17:31 jberger I'm not saying there is a problem, I just thought that the warmup did that and it doesn't seem to
17:32 sri ah no, it is based on app->renderer->classes
17:32 sri you're supposed to have preloaded those when you add them
17:33 sri DATA in controllers was never much of a concern to me btw.
17:33 jberger https://github.com/kraih/mojo/commit/54f0926c118efa2512c0ffec76def0a5aebec8be
17:33 jberger it was about forking, so no I don't think they need to be preloaded
17:34 sri that was a really annoying bug
17:34 jberger yeah, its coming back to me
17:34 jberger templates rarely and randomly being empty IIRC
17:34 sri same file descriptor in all forked processes and they seek randomly around corrupting each others reads
17:35 sri sometimes, resulting in garbled DATA templates in some worker processes and not others
17:36 sri think it took like 2 years to fix
17:36 sri since it was seen so rarely
17:39 jberger <3 the new github feature in the blame view where you can skip to the blame view of the commit before the one on any given line
17:39 jberger so nice
17:40 pink_mist ohh, that's great! been doing that the hard way for way too long
17:41 mohawk jberger, no thoughts on https://github.com/kraih/mojo/issues/1181 ?
17:42 mohawk pink_mist, thanks for the +1 :-)
17:42 jberger haven't had the time, sorry
17:45 jberger commented
18:00 mohawk jberger, nice thought! i agree
18:57 djk joined #mojo
19:01 Seth joined #mojo
19:15 Kharec joined #mojo
19:46 mib_8xswp5 joined #mojo
20:19 marty joined #mojo
20:46 AndrewIsh joined #mojo
21:03 jamesaxl joined #mojo
22:43 tianon joined #mojo
23:05 marty joined #mojo
23:08 jacoby joined #mojo
23:08 stephen joined #mojo
23:40 maschine is there any reason % if (session 'foo' == $bar) { ... } can't work?  I can pass it to a variable $foo first, but it's kinda clunky looking
23:44 cfedde joined #mojo
23:46 pink_mist does that deparse as session(foo) == $bar or does it deparse as session(foo == $bar)?
23:46 pink_mist err, I missed the '
23:50 maschine I would think session(foo) == $bar
23:50 maschine maybe that's why it doesn't work like I expect
23:52 marty joined #mojo
23:52 maschine % if ((session 'foo') == $bar) { ... } works - thanks for the clue pink_mist :)
23:53 pink_mist np =)

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