Wednesday, November 22, 2006

my girl is an US teleplay FAN

yeah, Lost, Desperate Housewives, and Prison Break. :)

--
Fayland Lam // http://www.fayland.org/

Friday, November 17, 2006

my fund

YES. 总算是守得云开见日月了。

总本金 14,000.00 总收益 1,025.07 总收益率 7.32%

--
Fayland Lam // http://www.fayland.org/

hello

it's from email post. thank Blogger.

PS, that's a pity that I can't visit beta.blogger.com for this moment. but thank Google, I can use email to post Blog now.

--
Fayland Lam // http://www.fayland.org/

Labels:

learning non-stop

mm, busy with my work. but I still need to learn a lot.
scheduler:
Haskell and Perl 6
Catalyst Chained, Action, COMPONENT
DBIx-Class Relationship and other stuff.
Locale::Maketext for multi-language

somehow I want to write a Plugin for Catalyst to set priority for Regex. u know I hate the url mapping of Regex these days.

bye
Friday, November 03, 2006

Catalyst response->redirect and login trick

say, u have a "return $c->res->redirect('/login') unless ($c->user_exists);" in one sub(means one url like "/forum/1/topic/new"). and u tried to get "/forum/1/topic/new" as $c->req->referer; but Catalyst is somehow different, u don't get "/forum/1/topic/new" as your HTTP_REFERER. Catalyst treats $c->res->redirect inside.

mm, maybe you will get this problem when you code in Catalyst.
Here comes my solution:
Root.pm
sub end : Private {
my ( $self, $c ) = @_;

# for login using!
if ($c->res->location and $c->res->location eq '/login') {
$c->res->location('/login?referer=/' . $c->req->path);
}
return if ($c->res->body || $c->res->redirect);
Logon.pm after $c->login OK, use
# redirect
my $referer = $c->req->param('referer');
if ($referer) {
$c->res->redirect($referer);
} else {
$c->res->redirect('/');
}
and in Template: try to put "<input type='hidden' name='referer' value='[% c.req.param('referer') %]' />" in your action='/login' form.

OK, maybe I forget the '$c->req->uri->query' or '$c->req->body_parameters', but you can improve it, right?

Have fun!

Labels:

Wednesday, November 01, 2006

Catalyst TT WRAPPER trick

Catalyst::View::TT has two different ways:
one is set a $c->stash->{template} then $c->forward($c->view)
the other is using $c->view('TT')->render
so if u want to have a hack on View::TT. better hack on 'sub render' since 'sub process' is calling 'sub render' indeed.

assuimg that we have a very common situation. we have a wrapper.html for whole site. but we don't want to apply the wrapper.html in email body templates and /admin pages.
according to this, we might have two solution.
one is to create two view modulues like TT.pm and NoWrapperTT.pm. config the WRAPPER.
the other is to do some trick on 'sub render' as what I did today.
sub render {
my $self = shift;
my ( $c, $template, $args ) = @_;

# view Catalyst::View::TT for more details
my $vars = {
(ref $args eq 'HASH' ? %$args : %{ $c->stash() }),
};

if ($vars->{no_wrapper}) {
$self->template->service->{WRAPPER} = [];
} else {
$self->template->service->{WRAPPER} = ['wrapper.html'];
}

$self->NEXT::render(@_);
}
so that u can use something like:
my $email_body= $c->view('TT')->render($c, 'email/example.html', {
no_wrapper => 1,
another_var => $another_var,
} );
or set $c->stash->{no_wrapper} = 1 in Admin.pm

have fun.
Refer: Code in GoogleCode

Labels: ,