[Catalyst] Weird problem with Catalyst::Authentication, and redirects

2011-01-26 Thread Ben van Staveren
Hi folks, I've been breaking my head over this one for the last 3 hours and I 
can't figure out what the hell is going on. I'm using Catalyst::Authentication 
to deal with authentication, as follows:


in Root.pm:

sub auto {
  my $self = shift;
  my $c = shift;

  if(!$c-user_exists) {
warn user does not exist\n;
$c-res-redirect('/login');
return 0;
  }
  return 1;
}

sub index :Path Args(0) {
  my $self = shift;
  my $c = shift;
  $c-res-redirect('/dashboard/');
}

So far so good, but... when loading up without being logged in, this happens:

user does not exist
[info] *** Request 4 (0.037/s) [4201] [Wed Jan 26 17:07:35 2011] ***
[debug] GET request for / from 127.0.0.1
[debug] Path is /
[debug] Found sessionid 130f7df91fcd9ca31c59eaa9c24f52de63d0c185 in cookie
[debug] Restored session 130f7df91fcd9ca31c59eaa9c24f52de63d0c185
[debug] Rendering template index.tt2
[debug] Redirecting to /dashboard/

Strangely enough, it seems that the c-res-redirect isn't taking for some 
reason, this used to work before, and suddenly stopped working. I've been 
trying to figure out what I've changed that would cause this, and I haven't 
touched any of the authentication bits at all.


If I am in fact logged in, c-res-redirect works exactly as advertised and 
will happily do the trick, except in this case where I have not logged in.


Any ideas? I'm about ready to shoot this project in the head :(

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Weird problem with Catalyst::Authentication, and redirects

2011-01-26 Thread Ben van Staveren

Hi Denny  list,


Have you tried turning it off and then on again?  ;)


Repeatedly :)


More seriously, I have found on multiple occasions that the Catalyst
Auth stuff can seem to get itself into an inconsistent state, such that
it starts behaving oddly (usually mine will successfully log in, but
fail to keep track of that fact), and the only way to fix it is to
delete the contents of the session store (database, in my case), delete
all the cookies for the site, and possibly wipe the browser cache too.

Other than that I'm not sure what to suggest.  Where does the auto
return to?  Is it possible it's coming back from there to before the
dashboard redirect, and so the redirect URL is getting overwritten
before the output is constructed?  (I've not used auto, so no idea if
this is a stupid question or not.)

On the off-hand of being wrong, as far as I know, auto is called before 
anything else is really done, so your dispatch chain ends up going


auto - action - end

I think. Anyways, I did clear the session store, zapped all the cookies, and 
the behaviour's still there. I did some Data::Dumper action, and even after 
the RenderView action class had it's way with things, the status is still set 
to 302, a Location header is present in the output, but it did render the 
template that it's not supposed to render.


Even if I do a $c-detach('end') and return 0, it will render a template, 
which by all accounts, it's not supposed to be doing.


Doing a telnet to the dev server and querying it does return the proper 
headers for a redirect as well; Status: 302 and Location: /login - but it also 
renders the output body, for some really freaky reason.


The main issue for me is that this behaviour seems to be triggered by 
something I did in controller code somewhere, but I could swear up and down 
that I haven't done anything that touches even remotely near authentication or 
the Auth guts, so I'm totally and utterly stumped. And it's kind of important 
this works, deadlines and such things :(


--

Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Weird problem with Catalyst::Authentication, and redirects

2011-01-26 Thread Ben van Staveren



-) check if all relevant modules are up to date.
-) try with a different browser
-) create a simple app and try this particular code there.
I would do this if it wasn't for the fact that this code has worked just fine 
for the past year, and I haven't done any updates or upgrades for the last 2 
weeks. And the problem is, if this is something that is due to C::A getting 
it's knickers in a twist, that's a showstopper for me because I can't go and 
tell my end-users yeah just clear your cache and try another browser, they'd 
lynch me on the spot.


I'll give it another shot, see what happens.

--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Weird problem with Catalyst::Authentication, and redirects

2011-01-26 Thread Ben van Staveren

*groan* that would've been the culprit.


- Fix bug accidentally introduced in the last version with response
  3xx statuses.

0.15 2011-01-04 14:19:36 CET
- Don't delegate to a view if the response body is set to `undef'.


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Transferring control via root/auto

2010-12-07 Thread Ben van Staveren
You want to $c-detach('end') -- unless that's the default these days. I 
use this pattern a lot and the only difference I see is that I do:


$c-detach('end') and return 0;
$c-res-redirect($c-uri_for($c-controller('Users')-action_for('loginedit'), 


[$c-user-id] ));
 $c-detach();

--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Begginer's question about application structure

2010-11-22 Thread Ben van Staveren

Personally (and this does mean personally), I'd do it as follows:

Your actual logic code (e.g. the whole deal of storing and retrieving 
things from the database) should be in a separate set of modules. Call 
those the 'backend' stuff. The main module here should be able to 
connect to the database on it's own, given the location of a config 
file, and it should be able to take an existing configuration and DB 
handle from Catalyst;


e.g.
my $backend = My::Backend-new(config_file = 'foo.cfg');

or

my $backend = My::Backend-new(config = $c-config, database = $c-model);

(the above isn't quite correct but forgot what I used myself).

Then you can easily wrap that into a Model; and do things like:

$c-model('Backend')-get_me_an_artist()

The advantage here being that you can also use your backend outside of 
Catalyst, so writing a console app becomes trivial at that point.


Sorry for the slightly disjointed reply but doing about 234413 things at 
the same time :D



Martin Bendix wrote:

Hi,

As a Perl and Catalyst novice, I have recently completed the online Catalyst 
tutorial, and read the Definitive Guide to Catalyst.  However, I have a few 
questions about the basic structure of a thin controller, fat model application.


I'd like to take my learning to the next stage by writing a fully functioning 
application, and the classic CD database seems like a good place to start - it 
will at least be of use to me when it's done.


Given the following basic criteria, I would be grateful for some high-level 
advice on how best to organise the application:


* I will be using DBIx::Class to access the database.
* At first, the initial user interface will be web based.
* I'd like to structure the application so that I can add additional interfaces 
with relative ease in future (e.g., command line, web services, etc.).
* I'd like to create test scripts for as many of the modules/application 
functions as possible.
* The application will provide the ability to create, search, update and delete 
artists, tracks, and CDs.


I think that my understanding of the following is correct, but I would 
appreciate any advice or pointers:


My model should be well separated from the controller.  Most, if not all of the 
application functionality should be exposed via the model, so that the Catalyst 
controller only needs to make simple calls to the model.  To do this, model 
classes should be created in 'lib/myapp', with simple adapters in 
'lib/myapp/Model', using Catalyst::Model::Adaptor.


At this point, I am a little less clear on how best to structure my application.

As my models will be primarily concerned with accessing the database, how much 
database code should go in my model classes, and how much in the 
DBIx::Class::ResultSet classes?  For example, should I write a method in my 
DBIx::Class::ResultSet classes that can add new CDs when supplied with title, 
artist and a track list?  Or would it be better to put this in my model?


Data validation could be handled by HTML::FormHandler, but any validation 
performed here won't be of much use if I later provide an alternative interface 
to my application.  I assume that I should therefore delegate validation to my 
model as well, so that the same validation methods can be used no matter what 
the interface?


Are there any good tutorials out there that cover this sort of thing?  At the 
moment, I'm more interested in best practices for structuring a Catalyst 
application than in the details of the code itself.  Are there any good open 
source Catalyst applications that I can look at to help me with this?  I've had 
a look at MojoMojo, but it's a little too complicated for me at the moment.



Many thanks,

Martin


  


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Forward on to other actions after removing first path segment?

2010-11-16 Thread Ben van Staveren



Request-URI: /2010-11-15/foo

* MyApp::_date is triggered
* Removes the date from the first path segment and stashes it
* Forwards to MyApp::Foo::index as if it was a fresh request and the 
date path segment was never there (except it is, in the stash).
I just realised I made a little mistake too, given that the chained 
action indeed triggers off something like /date - you could chain the 
date capture bit to / (PathPart '') but that might get you some 
unexpected results.


There are 2 solutions:

1) Use the 'default' action:

sub default :Private {
 my $self = shift;
 my $c = shift;
 my @requested_uri = (@_);

 my $potential_date = shift(@requested_uri);
 if($potential_date =~ /(\d{4}-\d{2}-\d{2})/) {
   $c-stash-{date} = $1;
   my $bit_after_date = shift(@requested_uri);
   my @remainder = @requested_uri;
   $c-detach('Your::Controller', $bit_after_date, [ @remainder ]);
 } else {
# 404?
 }
}

The above very much expanded to make clear what happens. If I go to the 
URI /2010-10-10/foo, it strips the date off and stashes it, and then 
forwards to Your::Controller-foo() - if I go to the URI 
/2010-10-10/foo/bar it will dispatch to Your::Controller-foo as well, 
but passes 'bar' as first argument (basically assuming that 'foo' is a 
:Local action)


Another option is to muck with the Catalyst internals a bit, I think 
there's a hook of sorts you can override in your controller that lets 
you examine the URI before it's dispatched to a controller, and it also 
lets you *modify* the URI before dispatching. Internal rewrite rules, as 
it were.


Wait, third option: use rewrite rules, as you mentioned, because in 
theory this means that if a date is there, it acts the same as if there 
is no date present, and you can always examine $ENV{DATE} to see if it's 
there.


The above might not be the best ways to get done what you want, but it's 
the best I can come up with late at night :) Maybe some other people can 
pitch in?


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Question about Chained Controller

2010-11-16 Thread Ben van Staveren



Charlie I use a :AuthRequired method attribute and check for that
Charlie in auto method. Is there anything inherently wrong with
Charlie that method? I got the technique from someone on this list
Charlie a while back.

When your requirements pile up, auto is going to become a big block of
monolithic code, and your methods are going to have enormous sequences of
attributes. Plus, I find it more logical to have the checking code
closer to where it's required, as opposed to having to maintain the
attributes scattered around the app then locate and edit the related
code in auto.
  
Depending on how much of your app is authentication-protected, you could 
reverse the idea; auth is checked unless an attribute :NoAuth is set. I 
found that if you have a Root controller that contains an index method 
that forwards to the proper place, a default method that generates your 
404 or forwards, and an auto method that deals with the global setup, 
things make a bit more sense. Optionally you can always put all your 
auth bits in one module, and use it from the Root controller and use the 
auto in Root to run your module against the current request and give the 
go-ahead.


Many ways to prevent your Root controller from becoming one bigass piece 
of spaghetti :)


Just my 2 cents

--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Forward on to other actions after removing first path segment?

2010-11-15 Thread Ben van Staveren

You want chained actions.

package MyApp;

sub _date :Chained('/') CaptureArgs(1) PathPart('date') {
 my $self = shift;
 my $c = shift;
 my $date = shift;

 $c-detach('invalid_date') unless($date =~ /^\d{4}-\d{2}-\d{2}/);
 $c-stash-{date} = $date;
}

sub something_using_the_date :Chained('/date') 
PathPart('something_using_the_date') {

 my $self = shift;
 my $c = shift;

 $c-res-body(Hi, you were looking for date:  . $c-stash-{date});
}

Dorian Taylor (Lists) wrote:

Hi all,

Suppose I want to have the first path match a pattern, like an 
ISO-8601 date. I then want to chop it out of the URI path and stash it 
and forward the request on to another handler in the fashion of 
mod_perl's $r-internal_redirect. Consider:


package MyApp;

sub _date :Regex('^(\d{4}-\d{2}-\d{2})$') {
  my ($self, $c, @args) = @_;
  $c-stash-{date} = $c-req-captures-[0];
  # OK now what goes here?
}

I'm ambiguous on two things:

1) I don't understand why an outside request to /foo will find its way 
to /foo/index in MyApp::Foo but a forwarded request will not. I 
understand I'm supposed to use 'visit' or 'go' but they don't seem to 
do it either.
2) I'm not entirely sure about the 'right' way to get the rest of the 
request-URI path. As a (.*) in the regex function attribute? Some 
other way?


Again, my desired effect is to process the rest of the URI path as if 
it was an outside request, after chopping off the first path segment 
and stashing it (if it matches a date).


Insights?

Thanks,

--
Dorian Taylor
Make things. Make sense.
http://doriantaylor.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/

Dev site: http://dev.catalyst.perl.org/



--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] error handling (Chain where ajax and non-ajax actions chain off)

2010-11-09 Thread Ben van Staveren
A bit offtopic but why use the trait at all, you can just check the 
x-requested-with header for the 'XMLHttpRequest' value - saves you a 
dependency. As far as the status_not_found routine, I suggest a liberal 
bit of cut 'n paste and using View::JSON (sort of negates the losing of 
one dependency if you give up the trait, unless you're using it already).


David Schmidt wrote:

Hello list

Both ajax and non-ajax actions chain off the same action
(base_with_id). If an error occurs (like the resource doesn't exist) I
detach to '/error404' in my Root Controller.
I just introduced the ajax stuff and before that 'error404' simply
rendered an error template. Now I'd like to check if it is an xmlhttp
request using 
http://search.cpan.org/~flora/Catalyst-TraitFor-Request-XMLHttpRequest-0.01/
and then either render the error template like before OR use the
status_not_found() helper from
http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.87/
  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Displaying template files without adding new controller actions

2010-10-11 Thread Ben van Staveren

Hi Anthony,

If you set up your webserver to not send any URL starting with '/static' 
to the Catalyst app, it's easy enough to just have static pages. Since 
you already know what data you are going to put in there, you can easily 
enough build an off-line script that runs as a cronjob and rebuilds the 
pages once every so often; or just add a function to your app that will 
rebuild things every now and then.


The other way to do it (and this is hackish), would be something like this:

sub default :Path {
 my $self = shift;
 my $c = shift;
 my $req_uri = $c-res-path;
 $req_uri =~ s/\/$//;
 # assume that you want the path bit + .tt2 on the end
  my $template = $req_uri . .tt2;
  
  if(-e $c-path_to('root','templates',$template)) {

$c-stash-{template} = $template;
  } else {
# the template doesn't exist
$c-stash-{template} = '404.tt2';
 }
}

This is, however, very non-optimal since you are hitting the filesystem 
for every request that wasn't satisfied by an existing action. Like I 
said, you can either let the webserver serve up static pages. If you are 
worried about how the URL looks in the browser, some mod_rewrite magic 
will fix that for you, but that's a subject for another list :)


YMMV, #include std_disclaimer,h, $self-keep_both_pieces if($broken), 
etc. etc. caveat emptor :)


 


Anthony Gladdish wrote:

-Original Message-
From: Denny [mailto:2...@denny.me]
Sent: 11 October 2010 15:22
To: The elegant MVC web framework
Subject: Re: [Catalyst] Displaying template files without adding new controller
actions

On Mon, 2010-10-11 at 15:02 +0100, Anthony Gladdish wrote:


I'd like to add various web pages to my Catalyst app without the need
to modify controllers and restarting the server.
Instead, I just want to add a Template::Toolkit .tt2 file on the file
system and it get picked up automatically.
  


  

That said, would you mind telling us a bit more about what you're
actually trying to achieve in your application?  There may be a better
or more standard way of doing it.



I want to add quite a few .tt2 pages to the app, in various directories.
I don't want to have to create a Controller action per added template page ( 
this is the only way I know of adding a web page to a Catalyst app ).
Every time I add a new page I'll have to add a new action to represent that 
page then restart the server. There must be a way to add as many template pages 
as required, and have a single Controller action display the web page if it's 
corresponding template exists, otherwise 404.

/app/example/one
/app/example/two
/app/example/three/a
/app/example/three/b

... each of these urls will map to a respective .tt2 template which the app 
will just forward to if it exists.

Suppose I had a 100 different ( fairly static content ) web pages - I really 
don't want to have to create an action for each.

Hope this helps.

Anthony
  



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] [Beginner] Understanding actions and controllers - not!

2010-08-23 Thread Ben van Staveren

try using /static/css/main.css ;)

Ekki Plicht (DF4OR) wrote:

Hi.
Somewhen over the weekend I had the impression that I em beginning to 
understand how actions and controllers work. I was wrong.


Starting with a bare minimum project, only using the standard root controller 
with three standard subs: index, default, end.


I created a view, then set up an 'index.tt' template, as well as a 
'error404.tt' template. index.tt contains the following line (via a wrapper):

link rel=stylesheet href=static/css/main.css type=text/css /

In the default action sub I have
$c-stash-{template} = 'error404.tt';

Using:
/localhost:3000/ - renders index.tt nicely
/localhost:3000/foo - renders error404.tt nicely
/localhost:3000/foo/bar - renders error404.tt broken, the css file is not 
found!


The debug screen says:
[info] *** Request 12 (0.000/s) [21763] [Mon Aug 23 23:02:52 2010] ***
[debug] GET request for foo/bar from 127.0.0.1
[debug] Path is /
[debug] Arguments are foo/bar
[debug] Rendering template error404.tt
[debug] Response Code: 404; Content-Type: text/html; charset=utf-8; Content-
Length: 3861
[info] Request took 0.100899s (9.911/s)
[...]

[info] *** Request 13 (0.000/s) [21763] [Mon Aug 23 23:02:52 2010] ***
[debug] GET request for foo/static/css/main.css from 127.0.0.1
[debug] Path is /
[debug] Arguments are foo/static/css/main.css
[debug] Rendering template error404.tt
[debug] Response Code: 404; Content-Type: text/html; charset=utf-8; Content-
Length: 3877
[info] Request took 0.101907s (9.813/s)
[...]

The default sub is declared as:
sub default :Path {


What am I missing here? Why is the first pathpart (1st argument) now suddenly 
prepended to my static path? All templates are in the same directory under 
root/


TIA,
Ekki

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] I18N with variables

2010-08-06 Thread Ben van Staveren
I've more or less given up on it, mostly because there are a few use 
cases where text needs translated that's not easily passed through 
c-loc, for example dynamically generated descriptions and such things. 
They *could* be put through c-loc but that ties some logic too tight to 
the whole web app for it to be worthwhile.


One thing I tend to do is just separate things to a ridiculous degree; 
instead of going [% c.loc('hi there') %], I'll in fact name it [% 
c.loc('index_tt2_hi_there') %] - which means that I need to translate 
for en_us as well (or at least put the text in). Inside perl modules, 
text that needs translated (e.g. modules that aren't tied to Catalyst), 
they all use another module I wrote that makes you register all 
different text identifiers, and will cache them; if you don't register 
it, you can't use it (error shows up), and once it's registered, another 
script will yank the cached entries and will merge them into an existing 
.po file if they need to be there.


There's also the issue that I'm dealing with now where I have a web shop 
that I need to build that needs to be fully bilingual. Including product 
descriptions and names - this makes things interesting because I18N is 
absolutely useless for it, so I'm building a set of modules that attempt 
to solve the whole problem gracefully; perhaps something to stick on 
CPAN at some point.


Cosimo Streppone wrote:
On Mon, 02 Aug 2010 07:08:04 +0200, Julien Sobrier 
jul...@sobrier.net wrote:



Also, writing [% c.loc(foo) %] does not create an entry in messages.po
when running xgettext.pl, like [% c.loc('foo') %] does.


To make that work, I think you'd have to actually *run*
your templates for all possible cases, and then collect all
the strings that were passed as arguments to c.loc().

In other words, I'm not saying it's impossible, but
xgettext.pl will probably never be able to do that.

A slightly different approach, that works for me,
is to create your .PO files in different stages.

First step parses the templates with xgettext.pl and generates
the .PO files.

A second step can, for example, parse the actual source
code, for stuff like '$c-loc(foo)'.
xgettext.pl can do that with a bit of trickery.

The new messages will be merged together in the same .PO files.

In your case, you could pull the messages you want to be translated
directly from the database, and write some on-the-fly
fake templates (or text files for that matter),
and feed them to xgettext.pl.



--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] I18N with variables

2010-08-06 Thread Ben van Staveren

Hi Matthias,

That's what I considered at some point, but what happens there is that 
you are more or less totally working around the I18N module at that 
point. I did some experimenting with a subclass of TT that was actually 
translation aware and would do it on a much lower level (given that I 
use TT for the web-facing end of the app, as well as for emails, 
generated files on disk, and even use it to an extend to generate 
shipping labels).


Matthias Dietrich wrote:

Hi,

Am 06.08.2010 um 14:58 schrieb Ben van Staveren:

  

There's also the issue that I'm dealing with now where I have a web shop that I 
need to build that needs to be fully bilingual. Including product descriptions 
and names - this makes things interesting because I18N is absolutely useless 
for it, so I'm building a set of modules that attempt to solve the whole 
problem gracefully; perhaps something to stick on CPAN at some point.



I'm using short identifiers for my I18N texts, like Home.Greeting which is then translated to Hi there for en_us or 
Hallöchen for de_de.  When I added a small CMS to a customer's application all texts should also be translated.  So I saved any 
text to I18N key CMS.NavigationPoint.PageKey.* within the right language file (actually I'm using C::P::I18N::DBI), * for 
Title or Content or similar.

I think it should be possible to handle product descriptions like this.  In 
your Backend save every text to Product.$ArticleNumber.Description, 
Product.$ArticleNumber.Name, Product.$ArticleNumber.Variant and so on where 
$ArticleNumber is the actual article number.  The possible languages should be 
somewhere in your Catalyst config.

Matthias

  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] I18N with variables

2010-08-06 Thread Ben van Staveren

Hi Bill,

Back in the day (heh) we faced the same problem for an app we were doing 
for a client, because the client insisted they wanted the ability to do 
their own translations, we ended up with text keyed on the location 
where it was called from, and the actual english string. So in a 
template we'd get


index.tt2(hello there, customer) as the key, but inside the template it 
was generated by doing [% f.xlat(hello there, customer) %] - or if you 
wanted parameters it was more like [% f.xlat(hello there, %, 
array_of_data) %].


We used one script that would just walk the template directory, and 
would set up the stash like this:


$stash = {
 f = {
   xlat = sub {
 my $string = shift;
 my @params = (@_);
 ...
   },
 },
};

We'd run it, and based on filename and the actual string passed it'd 
generate the master key file - some more scripts would look at 
duplicates (e.g. if more than one template contained the same string) 
and would generate a yaml configuration file containing a string = 
template mapping.


Similarly, inside perl modules we used the same mechanism, also 
described this in an earlier reply; where all translation strings *had* 
to be registered during module initialisation and it would then dump 
these to it's own master key file.


Rinse, repeat, merge. This then ended up going through the actual 
application's admin interface into the database, where it'd also flag 
everything that required translation into the available languages, so 
that the clients' translator team could go and take care of it.


In the end probably not the most graceful of solutions, and error-wise 
there were a few where certain phrases could have different meanings 
based on context but the code couldn't determine that - but usually that 
got fixed with a little rephrasing in choice locations :)


That's also the system I'm currently using in a slightly modified form 
for the webshop I'm building at the moment. I'll see if I can roll it 
all up into something distributable and put it online for download but 
that will have to happen some time later.



Bill Moseley wrote:



On Fri, Aug 6, 2010 at 6:16 AM, Matthias Dietrich mdietr...@cpan.org 
mailto:mdietr...@cpan.org wrote:


I'm using short identifiers for my I18N texts, like
Home.Greeting which is then translated to Hi there for en_us
or Hallöchen for de_de.  When I added a small CMS to a
customer's application all texts should also be translated.  So I
saved any text to I18N key CMS.NavigationPoint.PageKey.* within
the right language file (actually I'm using C::P::I18N::DBI), *
for Title or Content or similar.


I've been arguing with work about how to key our text.  So far we 
continue to use the English in the loc() tags in the templates, and 
then the I18N team uses a script to pull out this text which gets sent 
to translation services.


The risk is text gets into the templates that for some reason does not 
get pulled out.  The developers like the English in the templates as 
it makes them easy to read, and it means they don't really have to 
stop when entering new text.  Just seems like in the long run this 
will be unmaintainable and error prone.  (Well, not in the long run as 
it already is error prone.)


I've been arguing for a system where we use some kind of ID for the 
keys.  I'm not so sure the key format matters -- could be just a 
primary key in the db, for example.  This could be a stage done by the 
designers so the design spec just indicates a message id.  Then code 
development and translation can happen at the same time.


Is anyone using a system like that?  And more specifically, what 
application are you using to manage the translation database?  We have 
started to write one, but it's a bit more than trivial as we need it 
to work with different translation services, track history/changes, 
multiple applications, etc.  So, it would make more sense to use an 
existing tool.


So, I'd like to hear about your translation workflow and any tools you 
are using.


Thanks,


--
Bill Moseley
mose...@hank.org mailto:mose...@hank.org


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] How use two wrapper?

2010-06-06 Thread Ben van Staveren
Either set a stash variable indicating which wrapper you want to use, 
and modify your wrapper.tt2 as follows:


[% IF stash_variable == 'thiswrapper' %]
 [% WRAPPER thiswrapper.tt2 %]
   [% content %]
 [% END %]
[% ELSE %]
 [% WRAPPER thatwrapper.tt2%]
   [% content %]
 [% END %]
[% END %]

or just get rid of it altogether and set the right one in your templates.

Xiao Yafeng wrote:

Hi,
  I'm new to Catalyst. I'd like to use one wrapper to some 
templates, the other wrapper to some other templates. But as 
Catalyst;:Manual::Tutorial, 


I can only define one wrapper like this:
__PACKAGE__-config(
# Change default TT extension
TEMPLATE_EXTENSION = '.tt2',
# Set the location for TT files
INCLUDE_PATH = [
MyApp-path_to( 'root', 'src' ),
],
# Set to 1 for detailed timer stats in your HTML as comments
TIMER  = 0,
# This is your wrapper template located in the 'root/src'
WRAPPER = 'wrapper.tt2',
);
Thanks In advance!


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] DBIC connecting to remote MySQL

2010-05-23 Thread Ben van Staveren


script/easysaver_create.pl model ESDB DBIC::Schema EasySaver::Schema 
dbi:mysql:EasySaver:archeopteryx 'user' 'pass' '{ AutoCommit = 1 }'



We're getting closer now. Now I get an error that EasySaver::Schema
isn't found ... and the above didn't create it :(

  

My bad! Forgot one parameter...

script/easysaver_create.pl model ESDB DBIC::Schema EasySaver::Schema 
create=static dbi:mysql:EasySaver:archeopteryx 'user' 'pass' 
'{AutoCommit = 1}'


should do the trick :) Funny, you'd imagine the helper script would 
loudly complain if you don't tell it create=static but okay...


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Oddness with Catalyst::Plugin::Session::Store::DBIC

2010-04-28 Thread Ben van Staveren

Hi Matt,


Check your plugin order; this doesn't normally happen because Static::Simple
bypasses the loading of the session. If you've tried it both before and
after you load your session plugins, come back to us with the versions of
all the plugins you're loading and we'll dig further.
  

Current load order:

use Catalyst qw/-Debug
   ConfigLoader
   Unicode
   Compress
   Authentication
   Authorization::Roles
   Session
   Session::State::Cookie
   Session::Store::DBIC
   Static::Simple/;

This makes the weird happen. If I move Static::Simple to right after 
ConfigLoader, it still happens. Seeing as it happens when things go on 
with Session (e.g. Session updating itself for expiry time), it seems 
that plugin load order has no effect, unless there's some weirdness 
happening with another of those modules.


Like I said though, for me it's not a big deal that this happens, now 
that I know what causes it, I'm not worried about this showing up on my 
app_server.pl output during development. For production DBIC_TRACE is 
forced off and Static::Simple is never loaded :)


Thanks though :D



--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Oddness with Catalyst::Plugin::Session::Store::DBIC

2010-04-28 Thread Ben van Staveren



Which is great. But a lot of users leave Static::Simple loaded, so while
it's not going to bother you it -will- bother them.

So, in the name of paying karma forwards, any chance I could have the
versions anyway please?

  

*Cough* remind me not to answer emails late at night :D

Okay I've got the following:

Catalyst 5.80022
Static::Simple 0.29
Session 0.27
Session::Store::DBIC 0.11

--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Oddness with Catalyst::Plugin::Session::Store::DBIC

2010-04-27 Thread Ben van Staveren

Hi folks,

Recently after upgrading all of Catalyst, I'm witnessing some weird 
behaviour in some apps. I'm using Catalyst::Plugin::Session::Store::DBIC 
to store my sessions, and when I have DBIC_TRACE going, I see this:


BEGIN WORK
SELECT me.id, me.session_data, me.expires FROM session me WHERE ( me.id 
= ? ): 'session:fe3baeddb6ec2d3a14b07651a8792c7b85df9722'

COMMIT
UPDATE session SET expires = ? WHERE ( id = ? ): '1272443848', 
'session:fe3baeddb6ec2d3a14b07651a8792c7b85df9722

Not once per request, but up to 50 times in a single request. Is this 
something wrong in my code or is C::P::S::S::DBIC going nuts?


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Oddness with Catalyst::Plugin::Session::Store::DBIC

2010-04-27 Thread Ben van Staveren

Hi Moritz,

Yeah I just figured that one out - but that's new, never saw it do this 
before to be honest - it's not a big deal actually since in production 
Static::Simple isn't used and I let lighttpd take care of serving static 
files, but in testing it's a bit disconcerting to see it crop up all of 
a sudden :)


Thanks! :D

Moritz Onken wrote:

I had the same problem. I boiled it down to Static::Simple. Each request
to a static resource issued a session update. In a recent
release of cat the handling of requests seemed to have changed. 
Try downgrading to 5.80018 which fixed it for me (which is not a good

solution, but I have no time right know to fix it in catalyst or
write a test).


On Tue, 27 Apr 2010 15:42:21 +0700, Ben van Staveren
benvanstave...@gmail.com wrote:
  

Hi folks,

Recently after upgrading all of Catalyst, I'm witnessing some weird 
behaviour in some apps. I'm using Catalyst::Plugin::Session::Store::DBIC 
to store my sessions, and when I have DBIC_TRACE going, I see this:


BEGIN WORK
SELECT me.id, me.session_data, me.expires FROM session me WHERE ( me.id 
= ? ): 'session:fe3baeddb6ec2d3a14b07651a8792c7b85df9722'

COMMIT
UPDATE session SET expires = ? WHERE ( id = ? ): '1272443848', 
'session:fe3baeddb6ec2d3a14b07651a8792c7b85df9722

Not once per request, but up to 50 times in a single request. Is this 
something wrong in my code or is C::P::S::S::DBIC going nuts?



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON

2010-04-26 Thread Ben van Staveren

Looks like you need to set

expose_stash = 'json'

in your config.

Hetényi Csaba wrote:

Dear Rodrigo

I tired your tip, but my response is:

{json:[{value:Paddyfield Warbler,label:Paddyfield 
Warbler,id:Acrocephalus agricola}]}


and -of course- there is no any suggest. :(

I thought that Catalyst::View::JSON translate perl datastructures to
corresponding JSON data structure ( hash  object ... as i see on 
http://www.json.org) automatically. ( if not, i could use manually

created JSON formatted string without any JSON module)

Thank You!





Have you tried this?

sub request : Local {
my ($self,$c) = @_;
$c-stash-{json} = [ { id=Acrocephalus agricola, label= 
Paddyfield Warbler, value= Paddyfield Warbler } ];

$c-forward('View::JSON');
}

It gives me back the following response:

$ curl http://localhost:3000/request http://localhost:3000/test
[{value:Paddyfield Warbler,id:Acrocephalus 
agricola,label:Paddyfield Warbler}]


Which works with JQuery's autocomplete example just fine

-rodrigo




___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/

Dev site: http://dev.catalyst.perl.org/



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/

Dev site: http://dev.catalyst.perl.org/



--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON

2010-04-26 Thread Ben van Staveren

Probably not the most pretty one but:

Given you have a resultset obtained with, say,

my $result_set = $c-model('DB::Somedata')-search_rs({...}, {...});

$c-stash-{json} = [
 map { id = $_-id, label = $_-name } ($result_set-all)
 ];

Or a bit more verbose:

foreach my $result ($result_set-all) {
 push(@{$c-stash-{json}}, { id = $result-id, label = $result-name });
}

  `

Hetényi Csaba wrote:

Ahh!

That was the trick :)))
(expose_stash = 'json')

Now it is correctly translate the perl arrayref datastructure to JSON 
array ( [ ... ] )


my @aoh = (
{
   value  = 1,
   label = betty,
},
{
   value = 2,
   label= jane,
},

{
   value = 3,
   label= marge,
},
);
$c-stash-{json} = \...@aoh;
$c-forward('View::JSON');

:)

Thanks Ben!

One last question: if I have a DBIx resultset, how to use it to
populate autocomplete with the easiest way?

Best wishes from Hungary!




Ben van Staveren írta:
You can do that with View::JSON :) Just read the docs though, the 
reason it didn't work is that you put your data in


$c-stash-{json} = [ ... ]

And View::JSON will attempt to turn your entire stash into JSON data 
:) And it does that bit correctly, but the thing you end up with is


{
 json: [ ... ]
}

And autocomplete doesn't like that. So, either do:

$c-stash([ ... ])

Or set the expose_stash setting. Whatever is set in there, is the 
only thing that View::JSON will attempt to serialise.


Personally I prefer expose_stash = 'json', so that anything under 
$c-stash-{json} is serialised, but up to you :)










___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/

Dev site: http://dev.catalyst.perl.org/



--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Alternatives to Catalyst ?

2010-04-26 Thread Ben van Staveren



Why wouldn't you, as you write, use the the fastest access methods
available? Surely you'd want to develop habits that will a) provide
better performance and b) as mentioned below avoid the thorny
side-effects of req-params(). This isn't a matter of premature
optimisation but simply establishing good practise.

  
Because if you are working with, say, 10 people on a team, and you will 
have everyone merrily doing direct hash accesses, sooner or later, 
someone's going to fuck it up and something will break in a spectacular 
fashion.


If you have methods to do this, the methods can check various things, 
and throw out the proper errors.


Yes, a little bit of overhead -- the cost of hardware to compensate for 
this overhead is still less than the cost of a fuckup that will keep 
your app bugging for the rest of it's lifetime.


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Alternatives to Catalyst ?

2010-04-26 Thread Ben van Staveren



Because if you are working with, say, 10 people on a team, and you will have 
everyone merrily doing direct hash accesses, sooner or later, someone's going to 
fuck it up and something will break in a spectacular  fashion.



I take your point even though I am not in a team.

  
Even if you're not, direct hash accessing is basically akin to juggling 
grenades. It might go right for a long time, but eventually the pin's 
going to come out and there will be a very messy BLAM.


Even if it is code you just write for yourself, still doesn't hurt to 
make sure you avoid the BLAM bit :)


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON

2010-04-26 Thread Ben van Staveren
Used it but at the same time, doing my $hashref = { $row-get_columns } 
got me more or less the same effect for a lot less hassle :)


I actually do this for most my DB objects that get serialised to JSON, 
quite simple case of $c-stash-{json} = [ map { $_-get_columns } 
$rs-all ];


In a similar vein, I haven't yet really seen/heard any sort of best 
practices when it comes to Catalyst and JSON, so maybe I'm going about 
it all wrong but eh :)


Lee Aylward wrote:

On Mon, 26 Apr 2010 16:33:31 +0700
Ben van Staveren benvanstave...@gmail.com wrote:

  

Probably not the most pretty one but:

Given you have a resultset obtained with, say,

my $result_set = $c-model('DB::Somedata')-search_rs({...}, {...});

$c-stash-{json} = [
  map { id = $_-id, label = $_-name } ($result_set-all)
  ];

Or a bit more verbose:

foreach my $result ($result_set-all) {
  push(@{$c-stash-{json}}, { id = $result-id, label =
$result-name }); }

   `




I've also had good luck using DBIx::Class::RsultClass::HashRefInflator
in the past. It doesn't give you quite as much control, but it may be
enough for your needs.

http://search.cpan.org/~frew/DBIx-Class/lib/DBIx/Class/ResultClass/HashRefInflator.pm

  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Alternatives to Catalyst ?

2010-04-26 Thread Ben van Staveren

Hi Paul,

Don't get me wrong, but my opinion is pretty much opposite from yours, 
if people come and ask a good question (which Dermot did), and seem to 
be -not- total noobs, then they get a free CompSci lesson to go with the 
answer they've gotten :)


Maybe that's just me, but I always like knowing -why- a certain answer 
was given - besides just the this is how it should be kind of answer :)


Anyways, he got both the answer he was looking for, and some tips from 
people - perhaps some of us feel more strongly about it than others, but 
hey, that's what makes things interesting no?


Paul Makepeace wrote:

Even if you're not, direct hash accessing is basically akin to juggling
grenades. It might go right for a long time, but eventually the pin's going
to come out and there will be a very messy BLAM.

Even if it is code you just write for yourself, still doesn't hurt to make
sure you avoid the BLAM bit :)



(Replying in general, to the sense of this email which others have related too)

Dermot, to my reading at least, has been clear twice now that he was
asking specifically about how to retrieve parameters -- presumably not
coming to a web framework list for an unsolicited computer science
lecture on encapsulation...

I think it behooves us as a community to afford posters when they
clearly articulate a question and context, as Dermot has*, not to
treat them as complete noobs. It'd be a shame if folks became
reluctant to ask 'simple' questions for fear of half a dozen catalyst
old-skoolers delivering a sermon.

(Even these questions often reveal useful tidbits like the CGI compat hazard.)

Paul

* not the OP!

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Alternatives to Catalyst ?

2010-04-26 Thread Ben van Staveren



If using  -params-{name} (i.e. the direct hash approach) is like
juggling grenades - then what is like using the -param( 'name' ) way
of doing it?
  
Actually -params-{name} is the juggling teddybears one (the proper 
way to do it). If you do $c-{request}-{params}-{name} - that's the 
grenade way.


-.param('name') is juggling sharp knives :)


I am asking this because your grenades analogy gives the impression
that you you are against doing direct hash access for every price -
but I think the general advice is that in this particular case using
the -param( 'name' ) is worse than using the direct hash access.
  
Sorry if I wasn't quite clear on it, in the specific case of 
$c-req-params and consorts, doing $c-req-params-{ ... } is the 
right way to do it, after all, params returns a hashref and offers no 
further encapsulation; using -req-param('foo') would work, but is just 
a compatibility shim for CGI and comes with some major drawbacks.


I was, however, speaking in general; it's often better to be able to do 
$object-get_foo/$object-set_foot (or $object-foo which does both), 
than to go $object-{foo} = ...;


In some cases, it's not, sometimes you need to get rid of the overhead, 
but the common idea at that point is that IF you need to break 
encapsulation, comment it right, and indicate WHY you're doing it.





  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Alternatives to Catalyst ?

2010-04-23 Thread Ben van Staveren



I do not say that using hashes are good. But i'm sure that developers
MUST NOT use super-slow frameworks like Moose-shit (which tries to
emulate perl6 on perl5:   what for???) only to get good maintened
code. That's the own problems of developers how do they organize
internals. Why users of Catalyst must suffer from that ?  Or you wanna
tell that good maintened code must have a price of 100x slow down
??? that an absurdity can't you see it?
  
Cost of hardware to compensate the slowdown is generally speaking much 
less than the cost of programmers to maintain crappy spaghetti code.


Yes, Moose has overhead, quite significant at that during startup, but 
on the whole, those few CPU cycles aren't something you will be bothered 
by. Most servers these days have an abundance of them, you see. When you 
start hitting 100% CPU, you can most likely get better gains from 
streamlining the code you have as opposed to switching to the 1995 way 
of doing things.



It is possible to get good code (with MIXINS, C3, etc) without such a
great losses. If you see that something slows down application more
than 2x why do you use it? kick it off ! Benchmark.pm is your friend!

  
Lies, damn lies, and statistics. Benchmarking is nice, but benchmarks 
also tend to cloud issues. Yes, direct hash accesses are faster than 
going through an accessor which does validation. Simple matter of the 
latter needing more ops to do what it does.

Finnaly, you are creating framework for other people and the main
thing is how it looks outside, not inside.

  
Yes, at the same time, you're advocating that Catalyst should be coded 
according to your wishes and desires, in order to be faster. That's 
great, what about those of us who have to deal with maintaining large 
Catalyst  applications, where we care a bit more about the ease of 
maintenance than the cost of the hardware needed to run it.


On that note, by the time you have an app big enough to need more oomph, 
you're probably at a point in time where you can afford to pay this 
cost. Your average garden variety home-brew app doesn't need major 
horsepower, but it needs to be easily maintained.



Sorry for my hard post, i'm just a little nervious :(
  
Well, no hard feelings, but do try to back up statements like 'Moose 
shit' with facts ;)


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] strange generated DBIC accessor name

2010-03-10 Thread Ben van Staveren
DBIx::Class tends to pluralize relationships, so if you have a one to 
many relationship with a table company_person, it will name it 
company_people. Generally speaking this is also predictable :)


t...@dix.cz wrote:


Hello catal[yi]sters,

I'm going to be crazzy about one generated accessor name:

__PACKAGE__-has_many(
  company_people, # I expected to be company_persons
  Jf::Schema::Result::CompanyPerson,
  { foreign.role = self.id },
);

Other names seems to be predictable:

__PACKAGE__-has_many(
  company_addresses,
  Jf::Schema::Result::CompanyAddress,
  { foreign.role = self.id },
);


I have no people pattern in my database. Did I miss something?

The schema has been generated as usual:

script/jf_create.pl model DB DBIC::Schema Jf::Schema create=static \
'dbi:Pg:dbname=jf' tomas

Thanx,
Tomas

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/

Dev site: http://dev.catalyst.perl.org/



--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Check session expiry without extending it

2010-03-04 Thread Ben van Staveren
The way I got around this was by sticking all ajax stuff in a separate 
controller hierarchy that would return special content based on the 
request and whether or not the session lived. for json it'd just return 
a specific flag in the object it'd throw out (which was parsed by a 
global callback before calling my user defined stuff) that'd gracefully 
error the request for that, and any text/html would just output a script 
that'd toss up a dialog that said the session expired, and that the user 
should log in again.


Clunky, but it works, sort of.

Bill Moseley wrote:



On Thu, Mar 4, 2010 at 7:05 AM, Peter Karman pe...@peknet.com 
mailto:pe...@peknet.com wrote:



// make sure we are logged in before every xhr request
Ext.Ajax.on('beforerequest', function(conn, opts) {
   if (!AIR.Auth.isAuthenticated()) {
   AIR.Auth.login();
   return false;
   }
   return true;
});


I thought about this, but in our case the ajax was checking for a 
specific session because the server-side session had state info need 
for the ajax request.  So, just allowing the user to log in again was 
not possible.


That's probably bad design on top of bad design.  In our case probably 
better to rethink  then entire process and just make request that can 
be independent and either work or fail in some graceful way.  making 
assumptions about expected state is problem the root cause.


 


--
Bill Moseley
mose...@hank.org mailto:mose...@hank.org


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Automatic passing of objects to DBIx::Class

2010-02-27 Thread Ben van Staveren
I've ran into the same issue, but solved it in a bit of a hackish 
fashion. I went the route of the schema objects knowing nothing about 
the outside world, just themselves, and their relations with other 
schema objects.


On top of this sits a separate set of objects that contain all the logic 
necessary to make things work, using copious amounts of autoload 
voodoo. These objects can basically be used from any other app, be it 
Catalyst or some command line tool, and don't really have to know much 
else. For Catalyst I've got a custom model object that will return the 
appropriate logic object, whereas in offline tools they're used directly.


Sort of solves the problem in a cleaner way if you ask me.


Ido Perlmuter wrote:

Hi everyone.

I've been racking my brain trying to find a way to automatically pass 
an object, for the matter the Catalyst::Request object, to DBIx::Class 
methods. I cannot and will not pass it myself every time I call a 
method in my schema. While I do believe the model and the app should 
be completely separated, further information must flow between the two.


For example, I need to setup an administrative usage log for my app. 
Whenever a user with proper privileges invokes a schema method that 
creates, edits or deletes information from the database, I want that 
action to be automatically recorded in the usage log, with details 
such as the user ID and the user IP. I'm facing two difficulties: on 
one hand I believe this should be automatically done by the schema (so 
recording into the usage log will not be made from the app, but from 
the schema), but that means I need to pass the
context object (or the Request object) to every schema method I 
invoke; on the other hand, if I let the app handle recording into the 
usage log, my schema loses power. What if I want to write an API to my 
program in several programming languages, should they do the same too?


So for a while now I've been trying to find a way to automatically 
pass objects to the schema. Maybe if DBIx::Class was Moose-based I 
would have already found one using method modifiers.


Any thoughts will be appreciated.

Thanks,
Ido Perlmuter.


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] datetime formatting ...

2010-02-13 Thread Ben van Staveren
That's probably your database servers' time zone setting. If it's set to 
UTC you'd probably get that. You might want to add an 'on_connect_do' to 
your connection_info setting and execute the appropriate command to set 
the timezone you need (e.g. 'SET TIME ZONE LOCAL' or 'SET TIME ZONE 
Europe/Amsterdam' (for PostgreSQL this works, forgot what it is for MySQL)


Kiffin Gish wrote:

That worked, thanks. Only weird thing now is that the time is one hour
behind.

On Thu, 2010-02-11 at 12:45 -0300, Eden Cardim wrote:
  

Kiffin == Kiffin Gish kiffin.g...@planet.nl writes:
  

Kiffin I've got a datetime column defined:
__PACKAGE__- add_columns(
Kiffin   ...  last_modified, { data_type = DATETIME,
Kiffin default_value = undef, is_nullable = 1, size = undef, },
Kiffin );

Kiffin For some reason it's being displayed like this:

Kiffin 2010-01-05T20:35:14

Kiffin How can I get that 'T' out of there, replacing it with the
Kiffin usual space?

-last_modified-strftime('%F %T')

See perldoc DateTime for more formatting options.





  


--
Ben van Staveren
phone: +62 81 70777529
email: benvanstave...@gmail.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] C::P::Authentication, force user authentication

2009-12-29 Thread Ben van Staveren

On 28 Dec 2009, at 09:16, Ben van Staveren wrote:
Warning: I use this myself, it seems to work, but it's a hack. YMMV. 
Standard disclaimer applies.


I.e. It is very much relying on an implementation detail which I/we can 
and _will_ feel free to change at our leisure if needed.


Correct :) Like I said it's something I use in one spot, and I'm fully 
aware of the fact that it will break sooner or later, but for now it was 
the quick way to get the result I wanted.




___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] C::P::Authentication, force user authentication

2009-12-29 Thread Ben van Staveren

I.e. It is very much relying on an implementation detail which I/we can
and _will_ feel free to change at our leisure if needed.

Correct :) Like I said it's something I use in one spot, and I'm fully aware
of the fact that it will break sooner or later, but for now it was the
quick way to get the result I wanted.

But if I had to choose between your hack and using




$c-set_authenticated( $user, $realmname )
(given that it works, never tested it)

Id go with the latter for at least its documented.


True, also the reason I didn't use it -- setting a user to be 
authenticated without any interaction from said user is generally 
speaking a bad thing(tm), personally I want to make sure that this bit 
of code is in everyone's (well, okay, 3 people that work on it) mind as 
being out of place and in need of fixing.


Odd reasoning maybe to do it that way but it works for me :D




___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] C::P::Authentication, force user authentication

2009-12-28 Thread Ben van Staveren
It's a hack but it works... in a way. If you are using DBIx::Class, you 
can load the user record:


my $user = $c-model('YourUserModel')-find(userid);
$c-session-{__user} = { $user-get_columns };

As far as C::P::Authentication is concerned, the user is now 
authenticated. Forgot whether the key is __user or __user__ but just 
warn Dumper($c-session) at some point to see what it's supposed to be.


Warning: I use this myself, it seems to work, but it's a hack. YMMV. 
Standard disclaimer applies.


David Schmidt wrote:

Hello

When a user lost his password I send a digest by email.
If he enters this digest I want to automatically authenticate the user
so he can edit his password.

I only found this method but it says in the docs you shouldn't use it
in your code as it is an internal function only.
$c-set_authenticated( $user, $realmname )

Any other way to force user authentication?

thanks

david

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/