[Catalyst] Testing controller which require login.
I've been neglecting my test scripts, and I'm finally getting to that before my app gets any bigger. I want to make sure I don't break anything that's working, and that it works as well as I think it does. I'm probably going to have several questions in the next few days about tests. I think I've got a lot of the basics working; tests pass, I have a sensible test database and environment. I can see fixtures from here, I think. I haven't been able to get a test user logging in and out yet, though. I have several sections of my application that redirect the user away if they are not logged in. I have another that returns a 404 if they don't have access, so prying users can't find it (as easily). My tests are currently based on the stubs generated by myapp_create, and use Catalyst::Test. I could move them to WWW::Mechanize::Catalyst if it would help. I can't tell if Catalyst::Test supports cookies. Does it? Or do I need to use WWW::Mechanize::Catalyst for that? I've read some suggestions on how to go about this, and found a couple. 1> Use WWW::Mechanize::Catalyst to log the user in 2> Use the mock user in config to set a user who is logged in. The problem with really logging the user in is that the login is a set of site-wide cookies generated by a Single Sign On system. That system may or may not have a test instance running. If it does, cookies stored from it probably won't work with cookies from 'localhost' like the local test app wants. I can set a mock user, but then that user is always logged in. Can that mock user be changed by the test scripts, so I can have them log out, log in as an administrator, log in as an unprivileged user, etc, and test the pages perform correctly? If so, I've missed that - it would work, I think. The SSO is available to me as a library. I'm considering adding a login page to the application, so the test scripts can log in to the SSO through the application and solve the problem. Is duplicating a little code (not much, most of it is in a module) to make tests work a good idea? I'd want the application-specific login page to only be available while the test scripts are running. In production it shouldn't exist or at the worst redirect back to the real SSO login page. Writing a function which behaves differently in test seems like a source of errors to me. Does this sound possible? Can I just generate the cookie and put it in the cookie store directly before the query is made to the application? I can generate the cookie with the SSO library. I don't see a way to do that through either test tool. I'm trying to learn and do this in a maintainable, sensible way. Any help you can give is highly appreciated. -- Louis Erickson - lerick...@rdwarf.net - http://www.rdwarf.com/~wwonko/ It is the business of the future to be dangerous. -- Hawkwind ___ 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] More natural access to model?
Paweł Tęcza wrote: Dnia 2009-05-12, wto o godzinie 19:30 +0100, Matt S Trout pisze: Well, that's a horrible idea. The whole point of having a database is to -model- your data. If you try and turn it into a giant hash, then of course you're going to end up with nasty code. I -could- explain how to clean that loop up a lot, but the reality is that you should have actual columns for things and update your database as required as new types of data need to be included - you'll have to update the application anyway, so I don't see any reason not to update the database at the same time ... Intriguing post. My application and database design are still under heavy development, so all ideas, suggestions and comments are very welcome :D A general rule of thumb is that you should be conceptualizing your databases similar to how you conceptualize your applications. Your database schema, such as what tables you have, and their columns, and their column data types, and the relationships between tables and columns etc, these are like program code, such as how you choose to decompose your application into libraries and classes and class attributes and type constraints and input constraints and so on. The actual data you put in your database tables is analogous to what data you put in your application variables or objects. Generally speaking it should be natural to change your actual database schema as often as you change your application source code, where it makes sense; for example, changing your schema is a similar sort of operation to changing what attributes your object classes have or your constraints. Or more accurately in practice, a database is more like (or in some cases, exactly like) a shared library, where you have some classes you write once and share in multiple applications, and if you change the library you have to consider that impact on all the applications that use it. Hence people tend to be more conservative in database design changes, but still one shouldn't be afraid to do it, and all you really need is just proper communication and planning between the involved parties so it goes smoothly. Also, same as classes can have multiple APIs, eg keeping old ones for backwards compatibility if old apps can't update, databases have things called views / virtual tables which let them also have multiple APIs; this is one of the main purposes of views in fact. -- Darren Duncan ___ 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] My experience porting to CataMoose
On Wed, 2009-05-13 at 07:21 +0900, Daisuke Maki wrote: > >> 2. Hooking to methods that Plugins use via method modifiers breaks > >> method dispatch > >> > >> I got bit by this while depending on Catalyst::Plugin::Unicode, and > >> trying to hook a custom error handling mechanism at finalize(). > > > > > > > > Hmm, that certainally looks like a bug to me.. > > > > Any chance that I could get you to write a test case or two for this issue? > > I get it now, it has to do with when setup() and method modifiers run: > > > > If you intend to use Moose's method modifiers in your app, do so > /AFTER/ Catalyst->setup has been called. > > or some such First of all: thanks for the pointer, you have ended a lot of hair pulling for me. But IMO this is not just a common gotcha but a serious bug. I have a few plugins I am trying to convert to Moose::Role's that desperately need both before 'setup_components' and after 'finalize' This just isn't going to work one way or the other :( Maybe I can whip up some testcases tomorrow .. Cheers, Sebastian ___ 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] More natural access to model?
Dnia 2009-05-12, wto o godzinie 19:30 +0100, Matt S Trout pisze: > Well, that's a horrible idea. > > The whole point of having a database is to -model- your data. > > If you try and turn it into a giant hash, then of course you're going to > end up with nasty code. > > I -could- explain how to clean that loop up a lot, but the reality is that > you should have actual columns for things and update your database as > required as new types of data need to be included - you'll have to update > the application anyway, so I don't see any reason not to update the database > at the same time ... Hi Matt, Intriguing post. My application and database design are still under heavy development, so all ideas, suggestions and comments are very welcome :D My best regards, P. ___ 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] My experience porting to CataMoose
>> 2. Hooking to methods that Plugins use via method modifiers breaks >> method dispatch >> >> I got bit by this while depending on Catalyst::Plugin::Unicode, and >> trying to hook a custom error handling mechanism at finalize(). > > > > Hmm, that certainally looks like a bug to me.. > > Any chance that I could get you to write a test case or two for this issue? I get it now, it has to do with when setup() and method modifiers run: package MyApp; ... before finalize => sub { }; __PACKAGE__->setup( ... ); fails, but package MyApp; ... __PACKAGE__->setup( ... ); before finalize => sub { }; works. looks to me like a "Common gotchas" documentation. If you intend to use Moose's method modifiers in your app, do so /AFTER/ Catalyst->setup has been called. or some such --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] More natural access to model?
On Tue, May 12, 2009 at 11:45:01AM +0200, Paweł Tęcza wrote: > Dear Catalyst users, > > It's my first post here, so I would like to say "Hello" to all of us! :) > > I'm writing my first Catalyst application for student registration and I > have the following tables for details about studies at our university: > > CREATE TABLE studies ( > id integer NOT NULL, > unit_id integer, > status integer, > limit_soft integer, > limit_hard integer > ); > > 'id' column is a database study identifier. It's also primary key for > that table. 'unit_id' is an unit identifier of study, 'status' column > says whether registration is open/suspended/closed, 'limit_soft' and > 'limit_hard' are for student number limits. > > CREATE TABLE study_data ( > study_id integer NOT NULL, > lang lang NOT NULL, > name text NOT NULL, > value text > ); > > 'study_id' column is database study identifier (please look at > studies.id column), 'lang' column points language for (name, value) > pair, for example 'pl', 'en', etc. 'name' column is for name of data, > for example 'name', 'description', 'program', 'email', etc. > ('study_id', 'lang', 'name') is a primary key for that table. Finally > 'value' column is for data content. > > I think it's very simple structure and fully understandable for you, > so it doesn't need more comments. Of course, I can also define > table 'study_data' with many columns, for example 'name', 'description', > 'program', 'email', etc. but I think that its simpler structure is > better idea here, because it's more flexible. I can add new type of > data, without changing table definition. Well, that's a horrible idea. The whole point of having a database is to -model- your data. If you try and turn it into a giant hash, then of course you're going to end up with nasty code. I -could- explain how to clean that loop up a lot, but the reality is that you should have actual columns for things and update your database as required as new types of data need to be included - you'll have to update the application anyway, so I don't see any reason not to update the database at the same time ... -- Matt S Trout Catalyst and DBIx::Class consultancy with a clue Technical Director and a commit bit: http://shadowcat.co.uk/catalyst/ Shadowcat Systems Limited mst (@) shadowcat.co.ukhttp://shadowcat.co.uk/blog/matt-s-trout/ ___ 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] Who wants to be rid of the "Unknown Error" w/attributes bug on 5.10?
On Mon, May 11, 2009 at 06:28:12PM -0500, Andrew Rodland wrote: > On Monday 11 May 2009 05:45:01 pm Jonathan Rockway wrote: > > Or, you can use Debian, which fixed this bug in its Perl a while ago: > > > > http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=488088 > > > Not everyone uses Debian, and I, for one, would much rather be able to tell > people "get 5.10.1" than to have to explain what "patch" is or try to > convince > them to switch their operating system. A fix from upstream is long overdue. :) Right, so I'm asking the community to help. John, if you don't want to help, that's fine, you can remain part of the precipitate for all I care. Now, who wants to help and is there anything you need from me to make it easier for you to help out? -- Matt S Trout Catalyst and DBIx::Class consultancy with a clue Technical Director and a commit bit: http://shadowcat.co.uk/catalyst/ Shadowcat Systems Limited mst (@) shadowcat.co.ukhttp://shadowcat.co.uk/blog/matt-s-trout/ ___ 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] FormFu edit form problem
Am 11.05.2009 um 23:43 schrieb Steve Rippl: __PACKAGE__->belongs_to( "locationid", "WsdSis::Schema::Result::Location", { locationid => "locationid" }, ); should be __PACKAGE__->belongs_to( "locationid", "WsdSis::Schema::Result::Location", ); or __PACKAGE__->belongs_to( "locationid", "WsdSis::Schema::Result::Location", { 'foreign.locationid' => "self.locationid" }, ); ___ 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] More natural access to model?
Tomas Doran pisze: > Paweł Tęcza wrote: >> Thank you very much for your response! Is it a way to autogenerate all >> necessary subroutines in a loop or I need define all of them manually? >> They should have very similar body :) > > Here is the gross method: > > no strict 'refs'; > foreach my $name (qw/ method_one method_two /) { > *{$name} = sub { > my $self = shift; > # Your code here > }; > } > > > I'd instead recommend using Moose to do it for you: > > use Moose; > foreach my $name (qw/ method_one method_two /) { > __PACKAGE__->meta->add_method($name, sub { > my $self = shift; > # Your code here > }; > } > > This is (a) less icky, and (b) means that your generated code will come > out nicely in stack traces / error reports, rather than being 'ANON'. Hi Tom, Perl is great! Thanks a lot for these methods! It's very helpful for me. I'm your debtor now ;) My best regards, P. ___ 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] Installing Catalyst::Authentication::Store::DBIx::Class Breaks Catalyst
Hello, Collin I have the same configuration and output of the Catalyst config too! My problem is a bit different. I could login but the accounts that have 'admin' roles would never get detected of the 'admin' role. How are you doing with this issue? Guys, please comment. Thank you:) K. akimoto Quoting Collin Condray : > Tomas, > > Here's the config section of the debug output: > > do { > my $a = { > "Action::RenderView" => { > ignore_classes => [ > "DBIx::Class::ResultSource::Table", > "DBIx::Class::ResultSourceHandle", > "DateTime", > ], > scrubber_func => sub { "???" }, > }, > "Plugin::Authentication" => { > default_realm => "dbic", > realms => { > dbic => { > credential => { > class => "Password", > password_field => "password", > password_hash_type => "SHA-1", > password_type => "hashed", > }, > store => { > class => "DBIx::Class", > "ignore_fields_in_find" => [], > role_field => "role", > role_relation => "roles", > store_user_class => > "Catalyst::Authentication::Store::DBIx::Class::User", > user_class => "myappDB::Users", > }, > use_session => 1, > }, > }, > use_session => 1, > }, > "Plugin::ConfigLoader" => {}, > authentication => 'fix', > "custom-error-messsage" => { "error-template" => > "internal_error.tt", > "view-name" => "TToolkit" }, > email => ["Sendmail"], > home => "/home/.avis/username/domainname.com/myapp", > name => "myapp", > require_ssl => { no_cache => 0, remain_in_ssl => 1 }, > root => bless({ > dirs => [ > "", > "home", > ".avis", > "username", > "domainname.com", > "myapp", > "root", > ], > file_spec_class => undef, ___ 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] Need some help with Authorization setup
Quoting Kieren Diment : > Try prodding around your code with the debugger. Yep and done that. I could login without a problem just that the 'roles' never get populated. Any ideas to debug? > The docs are fine, and I think roles support should work out of the > box, but use the http credential, as it's easier to get up. 1) Nah, not using http credentials. The requirement/design for my app is to have user credentials stored in the database tables, users, user_roles and roles. 2) There's way too many docs available for Authorization and some vagueness about the effectiveness of the documentation. - headed to the docs for Catalyst::Plugin::Authorization::Roles - it doesn't describe the module, its purpose and so forth in good depth of detail - There's another reference link in that documentation that points to http://catalyst.perl.org/calendar/2005/24 - Headed over there and found that the article is obsolete. Been told to go to http://dev.catalyst.perl.org/wiki/gettingstarted/howtos/interim_authorization_and_authentication_example instead. - Headed over there and then it says that "The new Authentication tutorial is now available on CPAN. Please use that instead of the example below." - Headed over to the Catalyst tute, did whatever's needed there and yet I still have this issue of the roles not getting into the catalyst user object. 1) clearly, there's too many redirections - I hope someone can just delete the material that's no longer relevant (ie deprecated) 2) I need some help, guys as the catalyst tute for authorization doesn't work for me. I am using postgresql database as a backend. I seem to find that > > Put the following in Controller::Root: > > sub auto : Private { > my ($self, $c) = @_; > $c->authenticate; > } > > and then have a poke around with TT and with the debugger to see > what's missing or wrong in your setup. > may i ask how so? I'm in Login->index and I could authenticate just fine. I have tried dumping out the value of $c->user->roles and it's got nothing. Hel!! ___ 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] Handling of "keywords" for controller methods
Roland Lammel wrote: Here is the very simplistic patch, which only renames the "actions" attribute to "_controller_actions" in Catalyst::Controller. Test suite still passes with the patch and my app that originally showed that error, is now also working like a charm. Great stuff, change looks perfect. Could you also add an action named 'actions' to one of the TestApp controllers in the test suite, so that there is a regression test and evidence in the log/tests of _why_ this got changed? This should be fairly trivial, as adding just an empty method should cause everything to explode, right? TIA t0m ___ 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] Need some help with Authorization setup
kakim...@tpg.com.au wrote: What am I missing out? Please help. My apologies for the many files here. Hmm, hard to tell from just looking at the code. It'd probably be easier if you made a TestApp which just contains the code in question (i.e. small enough section to demonstrate your issue) and stuck a .tgz somewhere online (or uploaded the app to github).. Then someone could download and run your actual code with problems, making it a lot easier / quicker for someone to help out and spot what is wrong. Cheers t0m ___ 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] More natural access to model?
Paweł Tęcza wrote: Thank you very much for your response! Is it a way to autogenerate all necessary subroutines in a loop or I need define all of them manually? They should have very similar body :) Here is the gross method: no strict 'refs'; foreach my $name (qw/ method_one method_two /) { *{$name} = sub { my $self = shift; # Your code here }; } I'd instead recommend using Moose to do it for you: use Moose; foreach my $name (qw/ method_one method_two /) { __PACKAGE__->meta->add_method($name, sub { my $self = shift; # Your code here }; } This is (a) less icky, and (b) means that your generated code will come out nicely in stack traces / error reports, rather than being 'ANON'. Cheers t0m ___ 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] My experience porting to CataMoose
Daisuke Maki wrote: > I've switched an application of mine to CataMoose. Thanks for the hard > work, it's seems surprisingly stable for such a massive overhaul. Great, thanks a lot, and thanks for the feedback below! > I've observed a few glitches / gotchas, they seem like things that > probably should be documented, but I'd like to share with the list > before writing them up: > path_to will return something like "/whatever" instead of > "/path/to/MyApp/whatever", because home isn't set. to get around it, you > would need to force setup_home() to be called, or say > > package MyApp; > use Moose; > use Catalyst; # so import() gets called > > extends 'Catalyst'; > > __PACKAGE__->config(...); > __PACKAGE__->setup(...); Right, that's a documentation bug.. Fixed in r10091. > 2. Hooking to methods that Plugins use via method modifiers breaks > method dispatch > > I got bit by this while depending on Catalyst::Plugin::Unicode, and > trying to hook a custom error handling mechanism at finalize(). Hmm, that certainally looks like a bug to me.. Any chance that I could get you to write a test case or two for this issue? Cheers t0m ___ 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] More natural access to model?
Kieren Diment pisze: > On 12/05/2009, at 8:57 PM, Paweł Tęcza wrote: > >> >> Do you know solution of that issue? Maybe I should define >> subroutines in >> MyApp::Schema::ResultSet::Studies module for all type of data? >> > > Yes you should. That means that even though your code might be > horrible, you can hide the implementation details from the web > application portion of the code, and if you think about design > properly up front, removing the horrible code later on should be > pretty straightforward. Hello Kieren, Thank you very much for your response! Is it a way to autogenerate all necessary subroutines in a loop or I need define all of them manually? They should have very similar body :) Cheers, Pawel ___ 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] Need some help with Authorization setup
hello, Kieren, Good evening. Thank you and I shall get on it. K. akimoto Quoting Kieren Diment : > Try prodding around your code with the debugger. > > http://search.cpan.org/perldoc?Catalyst::Manual::Tutorial::Debugging ___ 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] More natural access to model?
On 12/05/2009, at 8:57 PM, Paweł Tęcza wrote: Do you know solution of that issue? Maybe I should define subroutines in MyApp::Schema::ResultSet::Studies module for all type of data? Yes you should. That means that even though your code might be horrible, you can hide the implementation details from the web application portion of the code, and if you think about design properly up front, removing the horrible code later on should be pretty straightforward. ___ 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] More natural access to model?
Zbigniew Lukasiak pisze: > 2009/5/12 Paweł Tęcza : >> So my question is: how can I modify my model to get the study details >> in the following, more "natural" way? Is it possibble at all? >> >> my @studies = $c->model('DB::Studies')->all; >> foreach my $study in (@studies) { >>$study_name= $study.study_datas.name|| ''; >>$study_description = $study.study_datas.description || ''; >>$study_program = $study.study_datas.program || ''; >>$study_email = $study.study_datas.email || ''; >> } >> > > Hmm - there is something missing there - according to your description > above $study.study_datas.program can not identify one value - but > rather an array of values (one for each language) isn't that true? > > You might also want to change the '.' to '->'. Hi Zbyszek, Thanks for your reply! Of course, you're absolutely right. I have to choose one language when I get all study details via my model. Sorry for confusing, but I rather wanted to show my problem than working snippet ;) Do you know solution of that issue? Maybe I should define subroutines in MyApp::Schema::ResultSet::Studies module for all type of data? Have a nice day, P. PS. I still remember your and Dexter presentation titled "Modern Perl" at the Faculty of Mathematics Informatics and Mechanics at the University of Warsaw in February :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] More natural access to model?
2009/5/12 Paweł Tęcza : > Dear Catalyst users, > > It's my first post here, so I would like to say "Hello" to all of us! :) > > I'm writing my first Catalyst application for student registration and I > have the following tables for details about studies at our university: > > CREATE TABLE studies ( > id integer NOT NULL, > unit_id integer, > status integer, > limit_soft integer, > limit_hard integer > ); > > 'id' column is a database study identifier. It's also primary key for > that table. 'unit_id' is an unit identifier of study, 'status' column > says whether registration is open/suspended/closed, 'limit_soft' and > 'limit_hard' are for student number limits. > > CREATE TABLE study_data ( > study_id integer NOT NULL, > lang lang NOT NULL, > name text NOT NULL, > value text > ); > > 'study_id' column is database study identifier (please look at > studies.id column), 'lang' column points language for (name, value) > pair, for example 'pl', 'en', etc. 'name' column is for name of data, > for example 'name', 'description', 'program', 'email', etc. > ('study_id', 'lang', 'name') is a primary key for that table. Finally > 'value' column is for data content. > > I think it's very simple structure and fully understandable for you, > so it doesn't need more comments. Of course, I can also define > table 'study_data' with many columns, for example 'name', 'description', > 'program', 'email', etc. but I think that its simpler structure is > better idea here, because it's more flexible. I can add new type of > data, without changing table definition. > > Unfortunately, when I want to get the study details, then I need to use > the code like below: > > my $study_name = ''; > my $study_description = ''; > my $study_program = ''; > my $study_email = ''; > > my @studies = $c->model('DB::Studies')->all; > foreach my $study in (@studies) { > my $name = $study.study_datas.name; > my $value = $study.study_datas.value; > > $study_name = $value if ($name eq 'name'); > $study_description = $value if ($name eq 'description'); > $study_program = $value if ($name eq 'program'); > $study_email = $value if ($name eq 'email'); > } > > I hope you agree with me that it's not handy way... > > So my question is: how can I modify my model to get the study details > in the following, more "natural" way? Is it possibble at all? > > my @studies = $c->model('DB::Studies')->all; > foreach my $study in (@studies) { > $study_name = $study.study_datas.name || ''; > $study_description = $study.study_datas.description || ''; > $study_program = $study.study_datas.program || ''; > $study_email = $study.study_datas.email || ''; > } > Hmm - there is something missing there - according to your description above $study.study_datas.program can not identify one value - but rather an array of values (one for each language) isn't that true? You might also want to change the '.' to '->'. -- Zbigniew Lukasiak http://brudnopis.blogspot.com/ http://perlalchemy.blogspot.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] More natural access to model?
Dear Catalyst users, It's my first post here, so I would like to say "Hello" to all of us! :) I'm writing my first Catalyst application for student registration and I have the following tables for details about studies at our university: CREATE TABLE studies ( id integer NOT NULL, unit_id integer, status integer, limit_soft integer, limit_hard integer ); 'id' column is a database study identifier. It's also primary key for that table. 'unit_id' is an unit identifier of study, 'status' column says whether registration is open/suspended/closed, 'limit_soft' and 'limit_hard' are for student number limits. CREATE TABLE study_data ( study_id integer NOT NULL, lang lang NOT NULL, name text NOT NULL, value text ); 'study_id' column is database study identifier (please look at studies.id column), 'lang' column points language for (name, value) pair, for example 'pl', 'en', etc. 'name' column is for name of data, for example 'name', 'description', 'program', 'email', etc. ('study_id', 'lang', 'name') is a primary key for that table. Finally 'value' column is for data content. I think it's very simple structure and fully understandable for you, so it doesn't need more comments. Of course, I can also define table 'study_data' with many columns, for example 'name', 'description', 'program', 'email', etc. but I think that its simpler structure is better idea here, because it's more flexible. I can add new type of data, without changing table definition. Unfortunately, when I want to get the study details, then I need to use the code like below: my $study_name= ''; my $study_description = ''; my $study_program = ''; my $study_email = ''; my @studies = $c->model('DB::Studies')->all; foreach my $study in (@studies) { my $name = $study.study_datas.name; my $value = $study.study_datas.value; $study_name= $value if ($name eq 'name'); $study_description = $value if ($name eq 'description'); $study_program = $value if ($name eq 'program'); $study_email = $value if ($name eq 'email'); } I hope you agree with me that it's not handy way... So my question is: how can I modify my model to get the study details in the following, more "natural" way? Is it possibble at all? my @studies = $c->model('DB::Studies')->all; foreach my $study in (@studies) { $study_name= $study.study_datas.name|| ''; $study_description = $study.study_datas.description || ''; $study_program = $study.study_datas.program || ''; $study_email = $study.study_datas.email || ''; } My best regards, Pawel ___ 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] My experience porting to CataMoose
2009/5/12 Daisuke Maki > Hi, > > I've switched an application of mine to CataMoose. Thanks for the hard > work, it's seems surprisingly stable for such a massive overhaul. > > I've observed a few glitches / gotchas, they seem like things that > probably should be documented, but I'd like to share with the list > before writing them up: > > 1. MyApp->config->{home} and Catalyst::Upgrading > > Catalyst::Upgrading suggests that the following is possible: > > package MyApp; > use Moose; > > extends 'Catalyst'; > > __PACKAGE__->setup( ... ); > > This is fine, but things gets a bit hairy when you mix this with calls > MyApp->config->{home} BEFORE setup(), for example: > > package MyApp; > use Moose; > > extends 'Catalyst'; > > __PACKAGE__->config( > 'View::TT' => { > INCLUDE_PATH => __PACKAGE__->path_to('whatever') > } > ); > [snip] My opinion on this is that this configuration style is inferior to using '__path_to(whatever)__', which is handled via ConfigLoader. The main reason is that I often times find myself cutting out and copying configuration into (conf|yml) files. Not that this is an excuse for the issue you have, but I just wanted to offer my (hopefully helpful) two cents. Thanks for the time you've spent, as well as blogging about it. -J ___ 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] Need some help with Authorization setup
Try prodding around your code with the debugger. http://search.cpan.org/perldoc?Catalyst::Manual::Tutorial::Debugging Also Catalyst::Helper::AuthDBIC on cpan. The docs are fine, and I think roles support should work out of the box, but use the http credential, as it's easier to get up. Put the following in Controller::Root: sub auto : Private { my ($self, $c) = @_; $c->authenticate; } and then have a poke around with TT and with the debugger to see what's missing or wrong in your setup. Also have a look at Catalyst::Controller::AuthDBIC On 12/05/2009, at 5:19 PM, kakim...@tpg.com.au wrote: hi, guys, I have looked at my codes again. I read a lot more and debugged a lot more. I have arrived at the point whereby my catalyst user object doesn't have any value for roles (despite all the values have been set in the database backend). What am I missing? For example, running the code which dumps a list of roles as per http://search.cpan.org/~hkclark/Catalyst-Manual-5.7021/lib/Catalyst/Manual/Tutorial/Authorization.pod#___top (title of Add Role-Specific Logic to the "Book List" Template") doesn't show anything but by right, my current user has an 'admin' role. What am I missing out? Please help. My apologies for the many files here. Thank you and help!! :) File Extract: lib/myApp.pm == use Catalyst qw( -Debug ConfigLoader Static::Simple StackTrace Authentication Authentication::Credential::Password Authorization::Roles Cache Cache::Store::FastMmap FormValidator Session Session::Store::FastMmap Session::State::Cookie ); __PACKAGE__->config( 'name'=> 'myApp', 'session' => { 'flash_to_stash' => 1 }, 'static' => { 'include_path' => [ $static_dir{'base'}, $static_dir{'user_media'}, ], }, 'Plugin::Authentication' => { default_realm => 'members', members => { credential => { class=> 'Password', password_field => 'password', password_type=> 'hashed', 'password_hash_type' => 'SHA-384', }, store => { class => 'DBIx::Class', user_model=> 'myAppDB::Users', role_relation => 'map_user_role', role_field=> 'role', }, }, }, 'default_view' => 'myApp::View::TT', ); File Extract: ~/projects/myApp/lib/myApp/Schema/Roles.pm package myApp::Schema::Roles; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components qw( TimeStamp Core ); __PACKAGE__->table("roles"); __PACKAGE__->add_columns( "id", { data_type => "integer", default_value => "nextval('roles_id_seq'::regclass)", is_nullable => 0, size => 4, }, "role", { data_type => "text", default_value => undef, is_nullable => 1, size => undef, }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("roles_pkey", ["id"]); # Created by DBIx::Class::Schema::Loader v0.04005 @ 2009-04-16 15:08:18 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7hanYe3kgzC1BJKgsYhH3g __PACKAGE__->has_many( 'map_user_role' => 'myApp::Schema::UserRoles', 'role_id'); 1; File Extract: ~/projects/myApp/lib/myApp/Schema/Users.pm use base 'DBIx::Class'; __PACKAGE__->load_components qw( TimeStamp Core ); __PACKAGE__->table("users"); __PACKAGE__->add_columns( "id", { data_type => "integer", default_value => "nextval('users_id_seq'::regclass)", is_nullable => 0, size => 4, }, "password", { data_type => "text", default_value => undef, is_nullable => 0, size => undef, }, "first_name", { data_type => "text", default_value => undef, is_nullable => 1, size => undef, }, "last_name", { data_type => "text", default_value => undef, is_nullable => 1, size => undef, }
Re: [Catalyst] Need some help with Authorization setup
hi, guys, I have looked at my codes again. I read a lot more and debugged a lot more. I have arrived at the point whereby my catalyst user object doesn't have any value for roles (despite all the values have been set in the database backend). What am I missing? For example, running the code which dumps a list of roles as per http://search.cpan.org/~hkclark/Catalyst-Manual-5.7021/lib/Catalyst/Manual/Tutorial/Authorization.pod#___top (title of Add Role-Specific Logic to the "Book List" Template") doesn't show anything but by right, my current user has an 'admin' role. What am I missing out? Please help. My apologies for the many files here. Thank you and help!! :) File Extract: lib/myApp.pm == use Catalyst qw( -Debug ConfigLoader Static::Simple StackTrace Authentication Authentication::Credential::Password Authorization::Roles Cache Cache::Store::FastMmap FormValidator Session Session::Store::FastMmap Session::State::Cookie ); __PACKAGE__->config( 'name'=> 'myApp', 'session' => { 'flash_to_stash' => 1 }, 'static' => { 'include_path' => [ $static_dir{'base'}, $static_dir{'user_media'}, ], }, 'Plugin::Authentication' => { default_realm => 'members', members => { credential => { class=> 'Password', password_field => 'password', password_type=> 'hashed', 'password_hash_type' => 'SHA-384', }, store => { class => 'DBIx::Class', user_model=> 'myAppDB::Users', role_relation => 'map_user_role', role_field=> 'role', }, }, }, 'default_view' => 'myApp::View::TT', ); File Extract: ~/projects/myApp/lib/myApp/Schema/Roles.pm package myApp::Schema::Roles; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components qw( TimeStamp Core ); __PACKAGE__->table("roles"); __PACKAGE__->add_columns( "id", { data_type => "integer", default_value => "nextval('roles_id_seq'::regclass)", is_nullable => 0, size => 4, }, "role", { data_type => "text", default_value => undef, is_nullable => 1, size => undef, }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("roles_pkey", ["id"]); # Created by DBIx::Class::Schema::Loader v0.04005 @ 2009-04-16 15:08:18 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7hanYe3kgzC1BJKgsYhH3g __PACKAGE__->has_many( 'map_user_role' => 'myApp::Schema::UserRoles', 'role_id'); 1; File Extract: ~/projects/myApp/lib/myApp/Schema/Users.pm use base 'DBIx::Class'; __PACKAGE__->load_components qw( TimeStamp Core ); __PACKAGE__->table("users"); __PACKAGE__->add_columns( "id", { data_type => "integer", default_value => "nextval('users_id_seq'::regclass)", is_nullable => 0, size => 4, }, "password", { data_type => "text", default_value => undef, is_nullable => 0, size => undef, }, "first_name", { data_type => "text", default_value => undef, is_nullable => 1, size => undef, }, "last_name", { data_type => "text", default_value => undef, is_nullable => 1, size => undef, }, "active", { data_type => "integer", default_value => undef, is_nullable => 1, size => 4 }, "main_contact_id", { data_type => "integer", default_value => undef, is_nullable => 1, size => 4 }, "company_name", { data_type => "text", default_value => undef, is_nullable => 1, size => undef, }, "billing_details_id", { data_type => "integer", default_value => undef, is_nullable => 1, size => 4 }, "billing_address_id", { data_type => "integer", default_value => undef, is_nullable => 1, size => 4