[Catalyst] Testing RESTful web services
Hi I am writing a simple test to test a POST method in a web service but my controller does not see any content in the POSTed request. In the controller both the $c-request-body and $c-request-content_length are undefined. Any ideas? -- test.t --- use strict; use warnings; use Catalyst::Test 'MyApp'; use HTTP::Request; my $req = HTTP::Request-new( 'POST', '/foo', [ Content_Type = 'text/plain' ], hello world, ); my $response = request($req); - ___ 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] Testing RESTful web services
Am 05.10.2008 um 10:47 schrieb Ian Docherty: Hi I am writing a simple test to test a POST method in a web service but my controller does not see any content in the POSTed request. In the controller both the $c-request-body and $c-request- content_length are undefined. Any ideas? -- test.t --- use strict; use warnings; use Catalyst::Test 'MyApp'; use HTTP::Request; my $req = HTTP::Request-new( 'POST', '/foo', [ Content_Type = 'text/plain' ], hello world, ); It's Content-type = ... ___ 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] Model--best practice help
Im going through my code, and trying to really think about how i can make it work well. Its a mess, i am realising, and i need advice on the best way to clean it up. Its clear that there are things in my Model that should be in a Controller; that i dont need help with. My problem is that i have two different Models, and dont know how they should be combined. In particular, im using DBIC, so i have a setup where i have MyApp::Schema::Main, which only looks like: package MyApp::Schema::Main; use base qw/DBIx::Class::Schema/; __PACKAGE__-load_classes(qw/Book Author/); 1; (the config stuff is in a separate config file:) Model::MyAppDB schema_class MyApp::Schema::Main connect_info ### /Model::MyAppDB Then i'll have MyApp::Schema::Main::Book of whatever that looks like package MyApp::Schema::Main::Book; use base qw/DBIx::Class/; __PACKAGE__-load_components(qw/PK::Auto Core/); (etc., other DBIC stuff) The problem is i also have a MyApp::Model::Book, and ive usually put non-DBIC things in there, like if i have a get_results method thats specific to my Cat app and not appropriate for the schema, ill put it there. That starts like package MyApp::Model::Book; use strict; use warnings; use base 'Catalyst::Model'; So ive got these two model classes, one i call with $c-model('MyAppDB::Book') and the other with $c-model('Book'). The problem is, i have some things that are Cat specific and i dont want them in my schema class (becaues i use this in non-Cat apps), but i dont want to have to have two separate models that i call by different names at different times. Whats the way im supposed to be setting these up? Thanks! Jen ___ 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] Model--best practice help
On Sun, Oct 5, 2008 at 10:03 AM, Dr. Jennifer Nussbaum [EMAIL PROTECTED] wrote: Im going through my code, and trying to really think about how i can make it work well. Its a mess, i am realising, and i need advice on the best way to clean it up. Its clear that there are things in my Model that should be in a Controller; that i dont need help with. My problem is that i have two different Models, and dont know how they should be combined. In particular, im using DBIC, so i have a setup where i have MyApp::Schema::Main, which only looks like: package MyApp::Schema::Main; use base qw/DBIx::Class::Schema/; __PACKAGE__-load_classes(qw/Book Author/); 1; (the config stuff is in a separate config file:) Model::MyAppDB schema_class MyApp::Schema::Main connect_info ### /Model::MyAppDB Then i'll have MyApp::Schema::Main::Book of whatever that looks like package MyApp::Schema::Main::Book; use base qw/DBIx::Class/; __PACKAGE__-load_components(qw/PK::Auto Core/); (etc., other DBIC stuff) The problem is i also have a MyApp::Model::Book, and ive usually put non-DBIC things in there, like if i have a get_results method thats specific to my Cat app and not appropriate for the schema, ill put it there. That starts like package MyApp::Model::Book; use strict; use warnings; use base 'Catalyst::Model'; So ive got these two model classes, one i call with $c-model('MyAppDB::Book') and the other with $c-model('Book'). The problem is, i have some things that are Cat specific and i dont want them in my schema class (becaues i use this in non-Cat apps), but i dont want to have to have two separate models that i call by different names at different times. Whats the way im supposed to be setting these up? Thanks! Jen Without seeing a tremendous amount of your code it is hard to answer, but it sounds like you are either at a point where it would be advantageous to learn Moose, or start doing some multiple inheritance hacks to get things working. The simple approach, which is much less great than using Moose, is to put your App specific (the Catalyst specific, as you phrased it) methods in a class, and then in your model class: package MyApp::Model::Everything; use base qw/Catalyst::Model::DBIC::Schema MyApp::Model::Book/; __PACKAGE__-config( ... ); 1; Then you can do $c-model('Everything')-foo_method( ... ); (foo_method defined in Model::Book), and still have $c-model('Everything::SchemaClass')-search(...); In foo_method, $self will be Catalyst::Model::DBIC::Schema, so you can do $self-schema-resultset('SchemaClass')-search(...); etc. But really... I'd just learn Moose, it'll make things easier and cleaner in the long run. -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] Model--best practice help
On Sun, Oct 5, 2008 at 2:03 PM, Dr. Jennifer Nussbaum [EMAIL PROTECTED] wrote: So ive got these two model classes, one i call with $c-model('MyAppDB::Book') and the other with $c-model('Book'). The problem is, i have some things that are Cat specific and i dont want them in my schema class (becaues i use this in non-Cat apps), but i dont want to have to have two separate models that i call by different names at different times. Whats the way im supposed to be setting these up? Create a class that's independent of Catalyst and glue it to your app via Catalyst::Component::InstancePerContext: package MyApp::Book; use Moose; has store = (isa = 'DBIx::Class::ResultSet', is = 'ro', required = 1); sub foo { shift-store-search(etc...) } sub bar { ... } ... package MyApp::Model::Book; use Moose; extends 'Catalyst::Model'; with 'Catalyst::Component::InstancePerContext' use MyApp::Book; has store_model_name (isa = 'Str', is = 'ro', required = 1); __PACKAGE__-config(store_model_name = 'MyAppDB::Book'); sub build_per_context_instance { my($self, $c) = @_; my $store = $c-model($self-store_model_name); return MyApp::Book-new(store = $store); } # in some distant controller: $c-model('Book')-foo; $c-model('Book')-bar; # runs on the same instance as the previous call -- edenc.vox.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] Success stories please
http://yourspace.codedright.net On Sun, Oct 5, 2008 at 3:04 PM, Matt S Trout [EMAIL PROTECTED] wrote: http://perlbuzz.com/2008/10/whats-the-state-of-perl-web-frameworks.html Shout out your support please, let's show the wider world that we're -the- real MVC option right now. And be honest - I don't think anybody thinks the docs are perfect or the learning curve's as shallow as it could be, but that doesn't mean Catalyst isn't still awesome. -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical Director http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Want a managed development or deployment platform? http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/ ___ 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/ -- Devin Austin http://www.dreamhost.com/r.cgi?326568/hosting.html - Host with DreamHost! ___ 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] Success stories please
http://perlbuzz.com/2008/10/whats-the-state-of-perl-web-frameworks.html Shout out your support please, let's show the wider world that we're -the- real MVC option right now. And be honest - I don't think anybody thinks the docs are perfect or the learning curve's as shallow as it could be, but that doesn't mean Catalyst isn't still awesome. -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical Directorhttp://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Want a managed development or deployment platform? http://chainsawblues.vox.com/http://www.shadowcat.co.uk/servers/ ___ 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] Success stories please
On Sunday 05 October 2008 06:16:57 pm Mark Keating wrote: On 6 Oct 2008, at 00:01, J. Shirley wrote: Andy apparently just wanted to start a flamewar. This article is idiotic, the reasons more so. I'm disappointed in perlbuzz in general as it now holds the same amount of respect as getting my news from The National Inquirer. I'd encourage people to rather blog about finding the article to be in poor taste, then post their success stories. Commenting here or on that blog entry is going to be buried. ++ to this Thirdeded. The best cure for Andy is to ignore him. Andrew ___ 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] Success stories please
* On Sun, Oct 05 2008, Andrew Rodland wrote: On Sunday 05 October 2008 06:16:57 pm Mark Keating wrote: On 6 Oct 2008, at 00:01, J. Shirley wrote: Andy apparently just wanted to start a flamewar. This article is idiotic, the reasons more so. I'm disappointed in perlbuzz in general as it now holds the same amount of respect as getting my news from The National Inquirer. I'd encourage people to rather blog about finding the article to be in poor taste, then post their success stories. Commenting here or on that blog entry is going to be buried. ++ to this Thirdeded. The best cure for Andy is to ignore him. BTW, I have to mention one of Andy's talks at OSCON: http://en.oreilly.com/oscon2008/public/schedule/detail/3001 It's called People for Geeks, i.e. how to be nice to people. If it's possible to die from an irony attack, you might not be seeing much more of me :) Regards, Jonathan Rockway -- print just = another = perl = hacker = if $,=$ ___ 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] Testing RESTful web services
Moritz Onken wrote: Am 05.10.2008 um 10:47 schrieb Ian Docherty: Hi I am writing a simple test to test a POST method in a web service but my controller does not see any content in the POSTed request. In the controller both the $c-request-body and $c-request-content_length are undefined. Any ideas? -- test.t --- use strict; use warnings; use Catalyst::Test 'MyApp'; use HTTP::Request; my $req = HTTP::Request-new( 'POST', '/foo', [ Content_Type = 'text/plain' ], hello world, ); It's Content-type = ... Yup, typo on my part, but it does not change the problem. There is still no content in the request when it gets to the controller. Just a slight modification to my original statement. In the controller the request body is undef, but the request length is 0 (not undef) Regards Ian ___ 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/