Skip to content

Instantly share code, notes, and snippets.

@pedrofaria
Created February 25, 2012 21:39
Show Gist options
  • Save pedrofaria/1910984 to your computer and use it in GitHub Desktop.
Save pedrofaria/1910984 to your computer and use it in GitHub Desktop.
import std;
import web;
Map<String, String> routes_get;
Int registerGet(String url, String callback) {
routes_get.insert(url, callback);
}
Int checkRoutes() {
String path = web.request::param('q');
Array<String> routes_re = routes_get.getKeys();
Array<String> routes_cb = routes_get.getValues();
for (Int i = 0; i < routes_re.size(); i++) {
Regex reg(routes_re[i]);
if (reg.matches(path)) {
println('found');
ReflectionFunction f( routes_cb[i] );
f.call();
return 1;
}
}
println('not found');
return 0;
}
Int run() {
web.session::header();
checkRoutes();
}
#!/Users/eu/src/clever/clever
import std;
import 'cleverfw.clv' as fw;
Void cb_home() {
println('ENTROU AKI!');
}
fw::registerGet("^home$", 'cb_home');
fw::registerGet("^opa$", 'cb_home');
fw::run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment