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

IRC log for #mojo, 2017-09-27

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

All times shown according to UTC.

Time Nick Message
00:34 aborazmeh joined #mojo
01:45 chandwki joined #mojo
01:54 ilbot2 joined #mojo
01:54 Topic for #mojo is now 🍩 nom nom | http://mojolicious.org | http://irclog.mojolicious.org | http://code-of-conduct.mojolicious.org
02:35 zivester joined #mojo
02:52 noganex joined #mojo
03:58 n16gel joined #mojo
04:04 dboehmer_ joined #mojo
04:12 jamesaxl joined #mojo
05:06 karjala_ joined #mojo
05:08 inokenty-w joined #mojo
05:44 leont_ joined #mojo
05:58 rshadow joined #mojo
05:59 dod joined #mojo
06:04 dod joined #mojo
06:08 dod joined #mojo
06:42 petru_ joined #mojo
06:57 AndrewIsh joined #mojo
07:14 Vandal joined #mojo
07:40 trone joined #mojo
07:53 rshadow joined #mojo
08:01 karjala_ joined #mojo
08:17 prg joined #mojo
08:49 n16gel joined #mojo
09:11 bianca joined #mojo
09:48 trone joined #mojo
10:24 trone joined #mojo
10:51 petru_ joined #mojo
11:00 dod joined #mojo
11:07 tchaves joined #mojo
11:16 bianca joined #mojo
11:49 itaipu joined #mojo
12:01 petru_ joined #mojo
12:24 * sri was wondering if anyone had put dash/zeal into website form already https://devdocs.io
12:27 sri actually pretty well done, you can choose which languages to cache for offline use
12:53 tcohen joined #mojo
12:59 gregf_ joined #mojo
13:05 itaipu joined #mojo
13:09 tyldis I'm a heavy user of it
13:09 tyldis Has been evolving very nicely
13:14 zivester joined #mojo
13:30 gizmomathboy joined #mojo
13:31 itaipu joined #mojo
14:00 gryphon joined #mojo
14:08 huddler joined #mojo
14:08 huddler hi
14:08 purl niihau, huddler.
14:09 huddler I'm trying to use an object in a template
14:09 huddler I put previously in session
14:09 huddler but when I try to access it's methods I get this exception
14:10 huddler Can't locate object method "has_role" via package "X::User=HASH(0x7f96f36ddd88)" (perhaps you forgot to load "X::User=HASH(0x7f96f36ddd88)"?) at template index.html.ep line 32.
14:11 huddler What am I doing wrong
14:11 huddler ?
14:12 huddler i tried to import (use) the module in the template as well as in the Mojolicious::Lite module but it does not seem to work ..
14:13 Vandal are you interpolating method call in string?
14:13 Vandal like "$foo->bar"
14:14 huddler no I'm doing this
14:14 huddler % if ($user->has_role('operator') || $user->has_role('admin') ) {
14:14 huddler to generate html dynamicaly
14:15 Vandal and where is the $user come from?
14:16 huddler from session
14:18 Vandal session data gets serialized if i recall correctly
14:18 ChmEarl joined #mojo
14:19 huddler should I cast it ... somehow?
14:19 Vandal how?
14:19 huddler no idea
14:20 Vandal you can't store object in session
14:21 maschine if you're (trying) to store store the objects in session anyway why not just save the 'roles' right in the session?
14:21 Vandal yep
14:23 Vandal IMO you cant avoid hitting db for propper user oblect if you need one
14:23 maschine what I did was assign a number to each "level" of authorization - so 0 would be a guest, 1 would be a user, 2, an admin, etc
14:24 maschine so I'd do something like % if ($user->{'auth'} > 1) { ... }
14:25 maschine then they'd get at least the privileges of the 'user' auth level, and guests wouldn't see it at all
14:25 maschine should be % if ($user->{'auth'} >= 1) { ... }
14:25 maschine instead of doing a bunch of || comparisons..
14:26 huddler so I can't get an object from session
14:26 huddler 100 % sure ?
14:27 huddler just hashes and scalars. Is it so?
14:27 Vandal huddler, docs says Mojolicious::Sessions manages sessions based on signed cookies for Mojolicious. All data gets serialized with Mojo::JSON and stored Base64 encoded on the client-side
14:27 maschine http://mojolicious.org/perldoc/Mojolicious/Sessions
14:28 Vandal huddler, so I think no
14:28 Vandal you need to create object again
14:29 huddler Yes, but the error is very specific ... (perhaps you forgot to load "X::User=HASH(0x7f96f36ddd88)"?) at template index.html.ep line 32. Don't you think?
14:29 maschine that's because the object doesn't exist
14:29 maschine it's telling you so :)
14:30 huddler thanks !
14:31 haarg because the object got stringified when you put it into the session
14:31 haarg and it's trying to use that string as a class name to call a method
14:38 huddler right, yes you are right
14:39 huddler can I put an array in session or only scalars?
14:46 maschine arrays and hashes should work fine
14:49 maschine http://mojolicious.org/perldoc/Mojolicious/Guides/Growing#State-keeping
14:50 jberger huddler: anything can be in the session as long as it is JSON serializable
14:51 jberger there is a practical size limit, browsers typically have cookie size restrictions
14:51 jberger I forget what they are but don't go crazy and it should be fine
14:52 jberger and I have used "objects" in my session by taking the data and inflating it back into an object early in the request phase
14:53 jberger when appropriate of course
14:53 maschine "which usually have a 4096 byte (4KiB) limit, depending on browser."
14:53 huddler how do you serialize / deserialize objects in perl
14:53 jberger maschine++
14:53 maschine don't know how accurate that is but that's in the mojo documentation
14:53 jberger huddler: if the object implements TO_JSON then it will serialize
14:53 maschine probably if you're storing more than 4k of data in a cookie though you're doing something wrong. :p
14:54 huddler and how do i deserialize it?
14:54 huddler mashine:: no , it just contains name and an array of roles .
14:55 jberger sub ($c) { $c->session->{user} = My::User::Class->new($c->session->{user}) ... }
14:55 jberger or something like it, early in the request phase
14:55 zivester joined #mojo
14:55 huddler ok.
14:56 jberger the TO_JSON would have to return the data necessary to re-inflate
14:56 jberger could be as simple as sub TO_JSON { {%{$_[0]}} } <-- untested
14:57 huddler fine, thank you!
14:58 jberger the only time I actually had to do that was when my $job[-2] had a requirement (that they didn't tell me about until the day before prod release) that users be able to log in as different accounts in different windows
14:58 jberger that was a bad day
14:58 maschine oh man...
14:59 jberger "so with this new (sane) login mechanism, how do we login as multiple users?" .... :o
14:59 maschine why would you want do do that.. lol
14:59 maschine even managing one login / auth / session is a pain as it is
14:59 jberger rather than giving users roles, they just made multiple accounts to each user
15:00 jberger so if the sales user also had access to billing they would have myname_sales and myname_billing
15:00 jberger because of course that's easier
15:00 maschine poor users
15:00 * jberger puke
15:00 maschine *nods
15:01 jberger the odd thing was, since every request was authenticated by a "token" (that was copied into each request by the previous request; it contained their hashed password, ugh) that scheme actually worked
15:01 jberger my first thing on seeing that was "oh dear gods that has to go, please please please can I redo that correctly"
15:01 jberger as one does
15:02 jberger and it got to the day before release that someone actually tried to use it in a work-like setting
15:02 maschine seems safe and secure, I don't know what your problem was. :p
15:02 jberger lesson #1: no one ever actually does UAT
15:02 jberger even if they promise you they did
15:03 jberger also their auth was super load intensive, each request took forever because of it
15:03 jberger using a cookie their latency went wayyyy down
15:04 jberger the solution I came up with was that each time they logged in it appeneded their user into an arrayref of users in their cookie
15:05 jberger and the pages had a way of selecting which user was appropriate for the page
15:05 jberger it was a hack, but it worked
15:05 jberger but it needed the user to be an object
15:05 jberger (with rather complex serialization)
15:06 maschine I don't get those problems because I mostly program to automate my own job
15:07 maschine *realizes that LISP has no simple way to do a string split
15:08 maschine I wish I could just use straight perl all the time..
15:23 itaipu joined #mojo
15:34 sh14 joined #mojo
15:48 dod joined #mojo
16:17 leont_ joined #mojo
16:24 leont_ joined #mojo
16:32 gregf_ joined #mojo
16:39 dod joined #mojo
16:42 dod joined #mojo
17:19 leont_ joined #mojo
17:23 petru_ joined #mojo
17:25 rshadow joined #mojo
17:34 Pyritic joined #mojo
17:51 rickbol joined #mojo
18:03 leont_ joined #mojo
18:04 rickbol joined #mojo
18:08 beyondcreed joined #mojo
18:08 petru_ joined #mojo
18:12 rickbol joined #mojo
18:22 rickbol_ joined #mojo
18:32 rickbol joined #mojo
19:04 rickbol joined #mojo
19:26 rickbol_ joined #mojo
19:41 rickbol joined #mojo
19:57 jberger zomg! someone used the mojolicious-universe mailing list
19:57 jberger \o\
19:57 jberger /o/
19:57 jberger I really was about to deprecate/close that
20:14 sri you should deprecate it anyway :p
20:15 sri one post in over a year
20:15 sri experiment failed
20:26 nchelluri joined #mojo
20:26 nchelluri hello, can someone help me with adding a Mojo::Template escape sub to a Mojolicious app? I don't know where to start.
20:27 rickbol joined #mojo
20:28 preaction nchelluri: do you have a Mojolicious app or a Mojolicious::Lite app?
20:28 nchelluri Mojolicious
20:29 preaction okay, so all the functions inside of your templates are "helpers", which you can add in your startup() sub in your main app by using $app->helper( "name" => sub { ... } );
20:29 preaction you can make plugins that contain helpers if you want: http://mojolicious.org/perldoc/Mojolicious/Guides/Rendering#Helper-plugins
20:30 nchelluri but I don't want a helper to use once: I want all content escaped using my sub
20:30 nchelluri all content rendered from templates
20:30 preaction escaped how? what are you doing?
20:30 Grinnz you mean you want to replace what's used to escape content in %= tags?
20:31 Grinnz instead of xml_escape?
20:31 nchelluri yes exactly Grinnz
20:31 preaction http://mojolicious.org/perldoc/Mojo/Template#escape there's this, but you'll have to find where, in the renderer, to set it
20:32 Grinnz i think you will need to re-register the EPRenderer plugin, passing {template => {escape => sub {...}}}
20:32 nchelluri ok, thanks, let me try that
20:54 karjala_ joined #mojo
20:57 rickbol_ joined #mojo
21:21 itaipu joined #mojo
22:00 mib_xh7q5w joined #mojo
22:46 zivester joined #mojo

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