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

IRC log for #mojo, 2015-08-02

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

All times shown according to UTC.

Time Nick Message
00:52 jontaylor_ joined #mojo
01:57 asarch joined #mojo
01:57 asarch How do you send the 'DELETE' method?
02:02 preaction with what?
02:02 preaction $ua->delete( 'url' ); seems to be how
02:06 asarch Can I do the same in EP?
02:07 preaction why would you want to send out a delete request when you're building a template?
02:08 asarch Well, I was trying to do something like:
02:08 asarch A have a list of students: /students
02:08 asarch And then you can check all the achievements for an specific student: /students/10/achievements
02:08 preaction what does this have to do with Embedded Perl?
02:09 damaya joined #mojo
02:09 asarch And doing the CRUD for the achievements, I could modify one of the specific student: /students/10/achievements/2/modify
02:09 preaction since you said all this in #catalyst, are you using catalyst or mojolicious?
02:09 asarch Both of them
02:10 damaya What's the best way to ensure a param is one of a set of allowable options?
02:10 asarch But I can't figure out how to "generate" the 'DELETE' and 'PUT' methods
02:10 damaya E.g., /:filter => in('latest', 'funny', 'etc');
02:10 preaction asarch: you use an ajax library
02:11 asarch I've been looking for a decent example all day long and so far I found: curl -X DELETE http://localhost:3000/
02:11 asarch Ajax?
02:11 damaya I'm doing this: if ( $filter !~ /opt|opt2|opt3/ ) { $filter = 'opt'; }
02:12 preaction asarch: Javascript. you use Javascript.
02:12 asarch https://en.wikipedia.org/wiki/XMLHttpRequest
02:12 preaction asarch: or you use a <form> and specify a method attribute
02:13 asarch Yeah! That was what I thought
02:13 preaction then why didn't you say that?
02:13 damaya asarch: Using jquery, http://api.jquery.com/jquery.ajax/
02:13 preaction or try it
02:13 asarch A <form> sending the 'POST' to cheat the 'DELETE' and 'PUT' methods
02:14 preaction what?
02:14 damaya asarch: With Ajax you can use PUT/DELETE.
02:14 preaction <form> tag has a method="" attribute
02:14 preaction that attribute _defaults_ to POST
02:14 preaction but i can be anything at all
02:14 damaya preaction: I don't think PUT/DELETE are supported as form methods
02:15 damaya Or, at least it didn't used to. Maybe it does now
02:15 preaction you can do it. it just doesn't make much sense
02:15 asarch I tried: delete => sub {my $c = shift; ...}; but since delete is also a reserved word for Perl...
02:15 damaya OK, I've never done it myself. I've always used Ajax for this.
02:15 preaction but PUT, why not? if the content is actually a url-form-encoded document
02:15 preaction asarch: that looks like you're just making things up now
02:17 asarch How would you catch the 'DELETE' method?
02:17 damaya asarch: I've used del 'route' => sub { }
02:17 preaction specify a route for the delete method
02:17 damaya It's in the documentation here: http://mojolicio.us/perldoc/Mojolicious/Lite#del
02:17 damaya Example is a Lite app.
02:29 damaya What does $validation->in return?
02:30 asarch ?
02:31 jontaylor_ joined #mojo
02:36 nnutter joined #mojo
02:38 damaya asarch: Nothing related to what you were asking. I was asking my own question regard params.
02:40 asarch Oh, sorry then
02:47 mattastrophe joined #mojo
02:47 noganex joined #mojo
02:49 damaya Is there something like $c->param->in(qw(one two three)); ?
02:59 asarch <form method='DELETE'> and <form method='PUT'> only send the 'GET' method :-(
03:00 preaction oh well. javascript it is then
03:01 asarch Oh, Ich spreche nicht JavaScript :'-(
03:02 asarch I will use the function damay says
03:02 preaction that doesn't send a delete request... that allows a route to match a delete request
03:06 asarch So: | Form |===>GET/POST===>| JQuery |===>DELETE===>| Controller | <- As if the form would send the 'DELETE' request?
03:06 preaction what?
03:07 preaction if you want to send a DELETE request to a server, you need to use JavaScript.
03:07 jberger Not true
03:07 preaction if you want to handle a DELETE request on the server, you make a route that accepts that DELETE method.
03:08 jberger Mojo has a query parameter for that
03:08 preaction and that won't work with Catalyst, which is apparently also involved here
03:09 damaya I guess what I am asking is how to have a restrictive placeholder with a default
03:10 jberger http://mojolicio.us/perldoc/Mojolicious/Guides/Routing#HTTP-methods
03:11 jberger asarch: ^^
03:11 jberger _method
03:11 jberger As a query parameter to a POST request
03:19 damaya I'd like to say, if param is not in this list, then param = 'foo'.
03:20 jberger damaya: you can do that in regular perl
03:20 damaya jberger: oh yeah, haha, that's how I'm doing it :D
03:21 damaya if ( $param !~ /list|of|acceptable|params/ ) { $param = 'foo'; }
03:21 damaya Was just wondering if there was a way to do it in the route.
03:21 damaya In the route's definition I should say. I don't know why I get caught up by these details constantly.
03:22 jberger You could write a shortcut, but meh
03:24 preaction you can use regex in routes
03:25 mst damaya: using regexp for that turns out to be IME an antipattern
03:26 preaction i'd avoid it too. seems more trouble than it's worth
03:26 damaya IME?
03:26 preaction in my experience
03:26 mst In My Experience
03:26 damaya so, if ( $filter eq 'foo' or $filter eq 'bar' or $filter eq 'baz' ) ?
03:26 preaction purl isn't here? ;_;
03:26 damaya Ah, OK, that's a new one for me
03:26 mst damaya: if you need that, you're misunderstanding routes, from my POV
03:26 preaction or just what you have up there, the regex
03:27 mst should be easy enough to turn that into a for loop
03:27 preaction what i was referring to was how you can do: $r->get( '/(foo|bar|baz)' )->to( ... )
03:27 mst yeah
03:27 damaya mst: Well, filter determines order by, and if they put /bullshit in there, there's no column bullshit.
03:28 mst I just think that's always an error
03:28 preaction yeah, it's going to be a really confusing time figuring that one out, i suspect
03:28 mst damaya: that's non-hierarchical therefore should be a query param
03:28 mst using it as part of the path is failing at HTTP
03:29 damaya My UI says: /us/oregon/funny (order by funny), but if they do /us/oregon/bullshit, there's a problem.
03:29 preaction /us/oregon?order_by=funny
03:29 mst damaya: so your UI is retarded
03:29 damaya interesting. I've tried to avoid query params as of late.
03:29 damaya mst: I designed it even, haha :D
03:29 preaction /us/oregon is the resource, the query parameter is a transformation of the resource
03:30 damaya ok, so don't avoid query params... fuck, now when (OK, thanks preaction for just answering my next Q).
03:30 mst damaya: most of the time when I say 'X is retarded' at work I desgined X
03:30 mst damaya: no insult implied
03:30 damaya haha
03:30 damaya none taken, I'm glad you've pointed it out.
03:30 preaction i only insult my own code, because i care about other people ;)
03:31 mst I insult all code, because it all sucks
03:31 mst especially mine
03:31 damaya I'd still have the issue of them doing a order_by=bullshit though
03:31 mst yes
03:31 mst I whitelist that
03:31 mst because some ORDER BY in queries is fine and some fucks the index usage
03:32 mst so it's more restrictive than 'is this a column'
03:34 mst damaya: the URI spec says 'path is for hierarchical, query for non' and ordering seems non hierarchical to me
03:34 preaction you wouldn't do: ls -l /var/log/by_date
03:34 mst also I have long seen "if you follow the HTTP and URI spec, the world works better than if you don't"
03:34 mst HATEOS is awesome
03:35 damaya ok, got it. Thanks mst and preaction.
03:36 damaya preaction: That really clears it up too, the `ls` example.
03:37 damaya I'd say Reddit is bad design then as well, right: https://www.reddit.com/r/Portland/top/
03:38 damaya it uses /r/subreddit/top, /r/subreddit/new, etc.
03:39 mst yeah, reddit is weird
03:39 damaya haha, ok that is really good to know then, because I often model my design on reddit
03:39 preaction those are subqueries of the main /r/board resource, so, kind of, yeah
03:45 damaya Does this look OK then: $r->get('/:country/:region/:type/:type_name') where valid URIs could be /us/oregon/metro/portland, /us/oregon, or /us/oregon/city/portland?
03:46 damaya And I set type to a default of state. So, by default it shows state data, but if type is metro or city, it grabs information related to that.
03:46 damaya Yes, I think in looking at that, it would be OK, because it is hierarchal (thinking about preaction's `ls` example).
03:47 damaya OK, answered my own question. Thanks everyone!
03:49 PryMar56 joined #mojo
03:53 mst damaya: yep. btw, don't let purity beat pragmatism
03:53 mst damaya: I used the hierarchical versus not as a heuristic and it's worked very well, but it's still only a heuristic :)
04:06 damaya mst: Definitely, but I like having my design decisions based on best practice. That's why I hate when there isn't a best practice :D
04:06 damaya Then I don't have to think about things too much
04:06 damaya haha
04:10 mst damaya: well the RFCs have helped me with that, but I can't be sure it works generally :)
04:14 dotandimet joined #mojo
04:35 jberger joined #mojo
04:51 zivester joined #mojo
04:59 mattastrophe joined #mojo
05:16 davido__ joined #mojo
06:24 dotandimet joined #mojo
06:35 Vandal joined #mojo
07:02 mattastrophe1 joined #mojo
07:02 jontaylor_ joined #mojo
07:20 damaya joined #mojo
08:07 sh4 joined #mojo
09:08 tyldis joined #mojo
09:15 jontaylor_ joined #mojo
10:30 amon joined #mojo
12:10 marty joined #mojo
12:14 chhikv joined #mojo
12:20 mattastrophe joined #mojo
12:34 chhikv joined #mojo
12:46 chhikv joined #mojo
12:54 lb joined #mojo
13:09 trone joined #mojo
13:17 stephen joined #mojo
13:32 bpmedley joined #mojo
14:26 marty_ joined #mojo
14:56 mattastrophe joined #mojo
15:02 kaare joined #mojo
16:01 PopeF joined #mojo
16:10 ajr_ joined #mojo
16:34 jontaylor_ joined #mojo
16:58 PryMar56 joined #mojo
17:13 jberger joined #mojo
18:03 jontaylor_ joined #mojo
18:13 davido__ joined #mojo
18:14 lluad joined #mojo
18:48 * jberger feels very manly
18:49 * jberger spent literally all morning cleaning his cat
18:49 jberger Hahaha
18:49 jberger Car
18:49 Grinnz <_<
18:50 jberger That poor cat
18:50 mst <insert pussy joke here>
18:50 jberger (I had intentionally avoided that)
18:53 jberger Fine I admit, I just couldn't come up with a good one
18:57 Grinnz your first pair of statements was good enough
19:56 theo joined #mojo
20:09 theo joined #mojo
20:11 zivester joined #mojo
20:36 inokenty-w joined #mojo
20:54 meshl joined #mojo
21:27 chhikv joined #mojo
21:34 dustinm joined #mojo
21:49 genio joined #mojo
22:04 thowe joined #mojo
22:05 bpmedley joined #mojo
22:35 genio joined #mojo
22:38 damaya joined #mojo
22:43 punter joined #mojo
22:44 Zoffix joined #mojo
22:46 damaya joined #mojo
23:23 mattastrophe joined #mojo
23:35 genio joined #mojo

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