Re: [Catalyst] Per request data in controller base class

2010-11-23 Thread Peter Karman
Bill Moseley wrote on 11/23/10 8:12 PM:

> Now, controllers can be chained together, so for example I might have a
> chain /cd/*/track/*/movement/* which all use the same base class, and
> where in the "movement" action I might want to be able to fetch the cd
> and track objects fetched when processing the chain.  So,
> $c->stash->{item} isn't such a good name.
> 
> One option might be for the base class to use its class name as a
> namespace in the stash.  That is, $c->stash->{CD}->{item} and
> $c->stash->{Track}->{item};
> 

Controllers may be chained together, but the URI that triggers the dispatched
action represents a unique item. I.e., the URI may describe a movement in
relationship to its parent track and its parent CD, but the URI describes the
*movement*.

But that might just be philosophical neither-nor-there.

In general, I find name-spacing the stash a useful exercise, esp when dealing
with multiple developers using the stash as they work on different parts of a
single dispatch chain.



-- 
Peter Karman  .  http://peknet.com/  .  pe...@peknet.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] Per request data in controller base class

2010-11-23 Thread Bill Moseley
I have a controller base class that needs to stash some data per request.
 My question is where to put that data (stash would seem best) -- and how to
name it.

This class is an auto-CRUD-like controller base class that does the mundane
work of fetching objects.  For example:

package MyApp::Controller::CD;
use parent 'My::Controller::CRUD';
1;

Which then will provided an action that handles "GET /cd/$id" which will
fetch the CD object and place it someplace.  For example, I could just put
it in $c->stash->{item}.

Now, controllers can be chained together, so for example I might have a
chain /cd/*/track/*/movement/* which all use the same base class, and where
in the "movement" action I might want to be able to fetch the cd and track
objects fetched when processing the chain.  So, $c->stash->{item} isn't such
a good name.

One option might be for the base class to use its class name as a namespace
in the stash.  That is, $c->stash->{CD}->{item} and
$c->stash->{Track}->{item};

Another option is to add attributes to the base class so I can then do:
 $c->controller( 'CD' )->item and $c->controller( 'Track' )->item;  But, I'd
need to be sure and clear those at the start of every request since this is
per-request data, unlike other attributes of the controller instance.

# Run before the root of chain action is run.
before 'base' => sub {
my ( $self, $c ) = @_;
$self->$_ for qw/ clear_item clear_item_id clear_resultset /;
};

Although that depends on the chain running to clear out the previous values.
 So, the stash is probably safer.

Of course, could still add methods of the same name $c->controller( 'CD'
)->item that is a wrapper for saving to or reading from the stash, although
that means $c would have to be available to the Controller.

So, where should this per-request data get saved, and what do you recommend
for naming?


BTW -- Catalyst::Component::ACCEPT_CONTEXT says "Make the current Catalyst
request context available in *Models and Views*".  Any reason not to use
this for Controllers?



-- 
Bill Moseley
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/


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

2010-11-23 Thread Bill Moseley
On Tue, Nov 23, 2010 at 8:16 AM, Sir Robert Burbridge wrote:

>
> By the way, I forgot to mention one piece of practical advice when
> determining what should be in your controller vs. model:
>
> *Write your controller first.*
>

Don't you mean second?  After writing the tests? ;)


-- 
Bill Moseley
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/


Re: [Catalyst] Catalyst::Authentication::Credential::OAuth

2010-11-23 Thread Hernan Lopes
To integrate facebook login onto your site,
Have you tried Catalyst::Authentication::Credential::FBConnect ?
It works and lets you access users facebook id from $c->user->session_uid as
documented

1. You need to register under http://developers.facebook.com and register a
new application. You must include the exact address you will use on the
machine for it to work ie. "http://localhost:3000/";

2. you need to configure include these onto your myapp.conf


default_realm   facebook



class   FBConnect
api_key my_app_key
secret  my_app_secret
app_namemy_app_name





3. you need a piece of javascript from facebook to create login button
(replace with your appId/fb_app_id as below):


sub login_facebook : Path('/loginfacebook') : Args(0) {
my ( $self, $c ) = @_;
my $fb_app_id = '';
$c->stash( template => \<




  window.fbAsyncInit = function() {
FB.init({appId: '$fb_app_id', status: true, cookie: true,
 xfbml: true});

FB.Event.subscribe('auth.sessionChange', function(response) {
  if (response.session) {
// A user has logged in, and a new cookie has been saved
window.location="/fblogin"; //redirects user to our facebook
login so we can validate him and get his user id.
  } else {
// The user has logged out, and the cookie has been cleared
window.location="/";
  }
});
  };

  (function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
  '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
  }());

FBLOGIN
);
}

4. then , i created an action  /fblogin to register facebook credentials
internally when user logs in (see in the js)

sub fbauthenticate :Path('/fblogin') :Args(0) {
my ($self, $c) = @_;
if ($c->authenticate()) {
$c->log->debug($c->user->session_uid);
$c->log->debug($c->user->session_key);
$c->log->debug($c->user->session_expires);
}
$c->res->redirect('/');
}


So remember, register at the http://developer.facebook.com with the same url
your application will use, include ports if its not 80

--Hernan


On Tue, Nov 23, 2010 at 8:32 PM, Blaine Everingham <
grandmasterbla...@hotmail.com> wrote:

>  Hi,
>
> I was wondering if anyone has a simple example of using OAuth with facebook
> to allow user login, to your software.
>
> I keep getting the error "oauth_parameters_absent:scope", but
> Catalyst::Authentication::Credential::OAuth document does not outline where
> you are supposed to enter this.
>
> Thanks,
> Blaine
>
> ___
> 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/


[Catalyst] Catalyst::Authentication::Credential::OAuth

2010-11-23 Thread Blaine Everingham

Hi,

I was wondering if anyone has a simple example of using OAuth with facebook to 
allow user login, to your software.

I keep getting the error "oauth_parameters_absent:scope", but 
Catalyst::Authentication::Credential::OAuth document does not outline where you 
are supposed to enter this.

Thanks,
Blaine
  ___
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] Re: Trying out FormHandler, running into "maketext" error

2010-11-23 Thread will trillich
Not sure what your "case sensitive" remark refers to -- and if it's looking
for something to be defined XXX that's defined xxx instead, that particular
error message is really out of left field.

Do you mean something like
   has_field 'submit'  => ( widget => 'submit' )
should instead be
has_field 'submit'  => ( widget => 'Submit' )
with a capital S?

The following is definitely working for us now:
has_field 'submit' => (type => 'Submit', label => 'Submit', value=>'Submit',
required => 0, )


On Tue, Nov 23, 2010 at 11:47 AM, Alexander Hartmaier <
alexander.hartma...@t-systems.at> wrote:

> Perl is case sensitive.
>
> Also you should not have any non Catalyst::Controller subclasses in the
> Controller namespace of your app.
> Move you forms to My::App::Form for example.
>
> --
> Best regards, Alex
>
>
> On Mon, 2010-11-22 at 18:25 +0100, will trillich wrote:
> > Ooh, very nice! Thanks so much, that's lots better now. Woo hoo!
> >
> >
> > Yes indeed, the "undef error - Unable to do maketext on:
> > at /usr/local/share/perl/5.10.0/HTML/FormHandler/I18N.pm line 15."
> > error has gone away thanks to tweaks to the SUBMIT button on the
> > FormHandler definition.
> >
> >
> > Was there something in the Catalyst/FormHanlder intro that we missed?
> >
> >
> >
> > On Mon, Nov 22, 2010 at 5:16 PM, Hernan Lopes 
> > wrote:
> > will trillich,
> > that error happens when i use  has_field 'submit'  => ( widget
> > => 'submit' )
> >
> > can you test your form with this instead:
> > has_field 'submit' => (type => 'Submit', label => 'Submit',
> > value=>'Submit', required => 0, )
> >
> > i bet your error will go away
> >
> >
> >
> >
> >
> >
> > On Mon, Nov 22, 2010 at 12:19 PM, will trillich
> >  wrote:
> > Our form-class includes
> >  has_field 'submit'  => ( widget => 'submit' )
> >
> >
> > Do you mean type=>'submit' instead of
> > widget=>'submit'?
> >
> >
> > Interesting that you'd think of this as a suspect.
> > What's the rationale?
> >
> >
> >
> >
> > On Mon, Nov 22, 2010 at 9:16 AM, Hernan Lopes
> >  wrote:
> > will trilich, are you using widget type
> > submit ? try to replace with type => 'Submit'
> >
> >
> > Hernan Lopes
> >
> >
> >
> > On Mon, Nov 22, 2010 at 1:38 AM, John Anderson
> >  wrote:
> >
> > On Nov 21, 2010, at 10:26 PM, will
> > trillich wrote:
> >
> > > Pooh. Still no luck. When we try a
> > more more Moose-y approach, we do get
> > updated database records (stuffing the
> > URL with arguments to affect a
> > form-submit) but still can't render,
> > with the same error as before:
> >
> >
> > Have you looked at the docs for
> > HTML::FormHandler::TraitFor::I18N?
> > Based on that, you may want to see if
> > you have something in
> > $ENV{LANGUAGE_HANDLE} or try passing
> > in a language handle to your form
> > constructor -- or may try push_errors
> > instead of add_errors, as that
> > documentation suggests.
> >
> >
> > 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/
> >
> >
> >
> > ___
> > 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/
> >
> >
> >
> >
> >
> > --
> > Failure is not important. How you overcome it, is.
> > -- Nick Vujicic
> >
> >
> > ___
> > List: Catalyst@lists.scsys.co.uk
> > Listinfo

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

2010-11-23 Thread Alexander Hartmaier
Have you thought about making the date a parameter instead of part of
the uri?

--
Best regards, Alex


On Mon, 2010-11-15 at 20:10 +0100, Dorian Taylor (Lists) wrote:
> Hi Larry,
>
> On 15-Nov-10, at 10:55 AM, Larry Leszczynski wrote:
>
> > Hi Dorian -
> >
> >> OK, but the part that confuses me is why /foo doesn't resolve to
> >> MyApp::Foo::index with ->go or ->visit.
> >
> > Maybe this will help (I think in this case "index" works like
> > "default"):
> >
> >   http://wiki.catalystframework.org/wiki/wikicookbook/safedispatchusingpath
>
>
> According to your wiki page, my solution is thus:
>
> package MyApp;
>
> sub _date :Regex('^(\d{4}-\d{2}-\d{2})(.*)$') {
>  my ($self, $c) = @_;
>  my ($date, $rest) = @{$c->req->captures};
>  $c->req->path($rest);
>  $c->dispatcher->prepare_action($c);
>  $c->go($c->action, $c->req->args);
> }
>
> This exhibits exactly the behaviour I was looking for.
>
> 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/


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be 
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

___
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-23 Thread Alexander Hartmaier
What's the advantage of Catalyst::Plugin::ConfigLoader::Multi over
setting the env var MY_APP_CONFIG_LOCAL_SUFFIX?
--
Best regards, Alex


On Mon, 2010-11-22 at 16:53 +0100, Martin Bendix wrote:
> > Have a look at this article
> > http://www.catalystframework.org/calendar/2007/14 which covers using
> > Catalyst models externally.
> > The code that goes with it is well out of date but should give you the
> > general idea using an external DBIC model class.
> >
> > Access to the model from a batch script:
> >http://dev.catalystframework.org/repos/Catalyst/trunk/examples/ExtJS/script/dump_bookings.pl
> >l
> >
> > Test script for model:
> >http://dev.catalystframework.org/repos/Catalyst/trunk/examples/ExtJS/t/10_schema.t
> >t
> >
> > Test scripts for web access:
> > http://dev.catalystframework.org/repos/Catalyst/trunk/examples/ExtJS/t/01app.t
>
> >http://dev.catalystframework.org/repos/Catalyst/trunk/examples/ExtJS/t/controller_ExtJS-Controller-ExtJS.t
> >t
> >
> > Some more pointers on testing:
> > http://dragonstaff.blogspot.com/2009/05/testing-with-perl-catalyst.html
> >
> >
> > Cheers, Peter
> > http://perl.dragonstaff.co.uk
>
> Hi Peter,
>
> Thanks for the great links.  I'd looked at the Advent Calendar articles
> previously, but hadn't remembered about the one you provided.  It looks very
> helpful, and I'll read it, and your information on testing, in more detail
> later.
>
>
>
> 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/


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be 
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

___
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] Re: Trying out FormHandler, running into "maketext" error

2010-11-23 Thread Alexander Hartmaier
Perl is case sensitive.

Also you should not have any non Catalyst::Controller subclasses in the
Controller namespace of your app.
Move you forms to My::App::Form for example.

--
Best regards, Alex


On Mon, 2010-11-22 at 18:25 +0100, will trillich wrote:
> Ooh, very nice! Thanks so much, that's lots better now. Woo hoo!
>
>
> Yes indeed, the "undef error - Unable to do maketext on:
> at /usr/local/share/perl/5.10.0/HTML/FormHandler/I18N.pm line 15."
> error has gone away thanks to tweaks to the SUBMIT button on the
> FormHandler definition.
>
>
> Was there something in the Catalyst/FormHanlder intro that we missed?
>
>
>
> On Mon, Nov 22, 2010 at 5:16 PM, Hernan Lopes 
> wrote:
> will trillich,
> that error happens when i use  has_field 'submit'  => ( widget
> => 'submit' )
>
> can you test your form with this instead:
> has_field 'submit' => (type => 'Submit', label => 'Submit',
> value=>'Submit', required => 0, )
>
> i bet your error will go away
>
>
>
>
>
>
> On Mon, Nov 22, 2010 at 12:19 PM, will trillich
>  wrote:
> Our form-class includes
>  has_field 'submit'  => ( widget => 'submit' )
>
>
> Do you mean type=>'submit' instead of
> widget=>'submit'?
>
>
> Interesting that you'd think of this as a suspect.
> What's the rationale?
>
>
>
>
> On Mon, Nov 22, 2010 at 9:16 AM, Hernan Lopes
>  wrote:
> will trilich, are you using widget type
> submit ? try to replace with type => 'Submit'
>
>
> Hernan Lopes
>
>
>
> On Mon, Nov 22, 2010 at 1:38 AM, John Anderson
>  wrote:
>
> On Nov 21, 2010, at 10:26 PM, will
> trillich wrote:
>
> > Pooh. Still no luck. When we try a
> more more Moose-y approach, we do get
> updated database records (stuffing the
> URL with arguments to affect a
> form-submit) but still can't render,
> with the same error as before:
>
>
> Have you looked at the docs for
> HTML::FormHandler::TraitFor::I18N?
> Based on that, you may want to see if
> you have something in
> $ENV{LANGUAGE_HANDLE} or try passing
> in a language handle to your form
> constructor -- or may try push_errors
> instead of add_errors, as that
> documentation suggests.
>
>
> 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/
>
>
>
> ___
> 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/
>
>
>
>
>
> --
> Failure is not important. How you overcome it, is.
> -- Nick Vujicic
>
>
> ___
> 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/
>
>
>
>
> --
> Failure is not important. How you overcome it, is.
> -- Nick Vujicic
>


*"*"*"*"*"*"*"*"*"*

Re: [Catalyst] Re: Converting a GET request to a POST request

2010-11-23 Thread Ronald J Kimball
On Mon, Nov 22, 2010 at 3:12 PM, Aristotle Pagaltzis  wrote:
> This is really, really, really bad. It’s roughly like modifying
> a file system to be allow file deletion as a side effect of
> opening a file. GET is supposed to be safe, that is, it should be
> free of side effects that the user cannot be held responsible
> for. It is very, very easy to get a browser to send GET requests
> incidentally, eg. by putting the link in a `` or
> a stylesheet `` and getting a user to visit. Things like
> Google Web Accelerator and other automated user agents (like
> search engines of course) also generally assume that GET is safe.
> Much web infrastructure also assumes that GET requests are
> cacheable, so if there are any proxies between the app and the
> user, sending multiple pseudo-POST requests may not actually do
> anything.

I completely understand the points you're making here.  As I said, one
of the drawbacks of this solution is that it makes me feel really
dirty.

For what it's worth, the REST methods that I want to expose in this
way are for posting responses to content.  There won't be any deletes.


> The same-origin policy is not there by mistake, but to keep your
> users safe from malicious 3rd party sites they may visit.

REST principles dictate that I use POST, not GET, for these requests.
The same-origin policy forces me to use JSONP, which can only make GET
requests, not POST.  What's the solution?


Ronald

___
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] Converting a GET request to a POST request

2010-11-23 Thread Ronald J Kimball
On Mon, Nov 22, 2010 at 7:33 PM, Tomas Doran  wrote:
>
> On 22 Nov 2010, at 18:28, Ronald J Kimball wrote:
>>
>> It doesn't care what the request method is, as long as it's POST, PUT,
>> OPTIONS, or DELETE.  ;)
>
> No, it just doesn't care.
>
>> If I create Catalyst::Action::Deserialize::JSONP, I'll still need to
>> convert the GET request to a POST.  That seems to be the really tricky
>> part.
>
> Why? Where is the code which forces it to be a POST?

In Catalyst::Action::Deserialize:

sub execute {
my $self = shift;
my ( $controller, $c ) = @_;

my @demethods = qw(POST PUT OPTIONS DELETE);
my $method= $c->request->method;
if ( grep /^$method$/, @demethods ) {
my ( $sclass, $sarg, $content_type ) =
  $self->_load_content_plugins( 'Catalyst::Action::Deserialize',
$controller, $c );
return 1 unless defined($sclass);
my $rc;
if ( defined($sarg) ) {
$rc = $sclass->execute( $controller, $c, $sarg );
} else {
$rc = $sclass->execute( $controller, $c );
}
if ( $rc eq "0" ) {
return $self->_unsupported_media_type( $c, $content_type );
} elsif ( $rc ne "1" ) {
return $self->_serialize_bad_request( $c, $content_type, $rc );
}
}

$self->maybe::next::method(@_);

return 1;
}


Ronald

___
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-23 Thread Sir Robert Burbridge



From: Sir Robert Burbridge
To: The elegant MVC web framework
Sent: Mon, 22 November, 2010 17:20:16
Subject: Re: [Catalyst] Begginer's question about application structure

I use DBIx::Class with multiple interfaces in the same app; this is the
structure I've found most useful so far:

 ### the lib dir.
 lib/

 ### MyApp stores everything relevant to my app
 lib/MyApp

 ### "MyApp::Web" stores the web interface
 lib/MyApp/Web
 lib/MyApp/Web/Model
 lib/MyApp/Web/View
 lib/MyApp/Web/Controller

 ### HTML::FormHandler forms that are web-specific.
 lib/MyApp/Web/Form

 ### Stores db stuff for DBIx::Class.
 lib/MyApp/Schema/

 ### Normal DBIx::Class schema, results, and resultsets
 lib/MyApp/Schema/MyApp
 lib/MyApp/Schema/MyApp/Result
 lib/MyApp/Schema/MyApp/ResultSet

 ### Schema/Result and Schema/ResultSet contain things like Moose roles
 ### that I want to apply to multiple models, but that really only make
 ### sense in the context of this application.
 lib/MyApp/Schema/Result
 lib/MyApp/Schema/ResultSet

 ### A namespace for script based access to the app
 lib/MyApp/Script
 lib/MyApp/Script/User
 lib/MyApp/Script/User/Create.pm
 lib/MyApp/Script/Report
 lib/MyApp/Script/Report/Documentation.pm

 ### Libs specific to the CLI
 lib/MyApp/CLI

 ### Tests
 t

 ### Store
 t/lib

A couple of notes:

The contents of lib/MyApp/Script are scripts that use MooseX::GetOpt.  I
added a helper script in script/myapp_utils.pl that allows me to do this
(this is mock output, but you get the idea).  In the example below, it
scans through the following namespaces in order:  MyApp::Script,
$ENV{MYAPP_SCRIPT_NAMESPACE}, CatalystX::Script, Catalyst::Script;
looking for ::Schema::Loader.

 ### Run with no arguments
 $ ./script/myapp_utils.pl
 Available scripts:

Report::Testing
Report::Documentation
Schema::Loader
User::Create
User::Modify
...

 $ ./script/myapp_utils.pl Schema::Loader
 An error has occurred: Required option missing: username
 usage: myapp_utils.pl [-?bdnpu] [long options...]
  -? --usage --help  Prints this usage information.
  -u --usr --user --username  A username with which to log into
 the db
  -p --pwd --pass --password  A password with which to log into
 the db
  -b --db --dsn  The DSN of the source database (e.g.
 "dbi:mysql:myapp")
  -d --dir --directory   a directory into which to install
 the schema
  -n --namespace the path to a directory

 $ ./script/myapp_utils.pl Schema::Loader \
 --user  ogopogo  \
 --pass  vonmugwumpus \
 --dsn   dbi:mysql:my_db  \
 --dir   lib  \
 --namespace MyApp::Schema::MyApp

 Creating schema ... done.

 $

Web forms are stored in the path like Halifax::Web::Form::CD::Create
(create a new CD from the script interface).

FWIW =)

-Sir
 

Hi,

Thanks for taking the time to put this information together.  There is some very
useful advice and ideas in there which I will take on board.  MooseX::GetOpt
looks very handy, and it's this sort of information - the tips and tricks of the
professionals if you like - that really help to advance the skills and knowledge
of others.


Regards,

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/
   

You're welcome =)

By the way, I forgot to mention one piece of practical advice when 
determining what should be in your controller vs. model:


_/*Write your controller first.*/_

The controller acts as a functional specification for your models; it's 
a "live test", so to speak.  So if you've got an Artist-CD sort of 
setup, use this process:


1) Figure out your URI schema (do you want /cd/928420249292/artists or 
/cd?id=928420249292&field=artists, or what?)
2) Once you figure out that you want /cd/928420249292/artists ;) write 
the controllers.  This is very important: /Write the controllers as 
though the models already exist, then implement models to the 
controllers/.  Write your controllers as though it's a perfect world, 
and your ideal models exist.  That means do things like:


   sub some_controller :Path :Args {
   ### Task:  sell 10 copies of a CD to a customer.
  $cd = $c->stash->{cd};
  $customer = $c->user;

  ### We could do the following:
  ###
  ###   my $quantity = 10;
  ###
  ###   ### Adjust the stock levels in the store
  ### $c->stash(remaining_stock => $cd->remaining_stock - $quantity);
  ###   $cd->popularity($cd->popularity + $quanti

Re: [Catalyst] Multiple chain sources?

2010-11-23 Thread Bill Crawford
On 23 November 2010 15:34, Oleg Kostyuk  wrote:

>   $c->forward( $action [, \...@arguments ] )

> As I think, $c->forward(user => [$c->user->id]) isn't one of them.
> So, what this should mean?

$c->forward( $action [, \...@arguments ])
$c->forward( 'user'   , [ $c->user->id ] )

The '=>' acts like the ',' but quotes its left hand side, hence the
lack of quoting around "user" in the example that you quoted. [0]

[0] No, I couldn't quite wrap my head around parsing this sentence either.

___
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] Multiple chain sources?

2010-11-23 Thread Oleg Kostyuk
2010/11/23 Eden Cardim :
> No, that's currently not possible with chained. Matt and I, howeever,
> are working on a grammar-based dispatcher that will allow easy
> expression of those types of constructs.

I would like to get more details about this.
Is it possible to get repo url, please?


> You'll have to declare something like:
>
> sub my :Chained('base') CaptureArgs(0) {
>  my($self, $c) = @_;
>  $c->forward(user => [$c->user->id]);
> }
>
> and then chain onto that.

Could you please explain, what is this?
As I see in Catalyst POD, for now we have two signatures for forward method:

   $c->forward( $action [, \...@arguments ] )
   $c->forward( $class, $method, [, \...@arguments ] )

As I think, $c->forward(user => [$c->user->id]) isn't one of them.
So, what this should mean?

Thanks in advance.

-- 
Sincerely yours,
Oleg Kostyuk (CUB-UANIC)

___
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] RE: DBI handle without "magic" when calling with dump_info=1 after updating Catalyst::Runtime

2010-11-23 Thread Jeremy Dack
Matt,

I have multiple views in my view folder but I am not using them at present;
however just their presence seems to be enough to cause the resultset error.


I've found that adding: 

$c->config->{'Action::RenderView'}->{ignore_classes} = [];

To my root sub end : ActionClass('RenderView') stops the error from
triggering. This seems to override it from ignoring the
DBIx::Class::ResultSource::Table & DBIx::Class::ResultSourceHandle as per
the RenderView.pm (see below).

$c->config->{'Action::RenderView'}->{ignore_classes} =
( ref($c->config->{'debug'}) eq 'HASH' ?
$c->config->{'debug'}->{ignore_classes} : undef )
|| [ qw/
DBIx::Class::ResultSource::Table
DBIx::Class::ResultSourceHandle
DateTime
/ ] unless exists
$c->config->{'Action::RenderView'}->{ignore_classes};

I have no idea why this fixes the issue as I have only just started playing
with Catalyst so I maybe talking rubbish however it has definitely solved my
issues.

Good luck

Jeremy.



-Original Message-
From: Matthias Dietrich [mailto:mdietr...@cpan.org] 
Sent: 23 November 2010 13:19
To: Jeremy Dack
Cc: The elegant MVC web framework
Subject: Re: DBI handle without "magic" when calling with dump_info=1 after
updating Catalyst::Runtime 

Hi Jeremy,

I cc'ed the list again so they all can see that we discuss about this :-).

Am 23.11.2010 um 14:13 schrieb Jeremy Dack:

> The problem seems to be with RenderView, do you use any custom views like
> JSON or is all your output HTML?

I use some other views than HTML in some apps, but this issue only occurs
when HTML (here: Mason) should be printed.  AFAIK it also occurs when only a
HTML/Mason view is available.

Matt

-- 
rainboxx Software Engineering
Matthias Dietrich

rainboxx Matthias Dietrich   |  Phone: +49 7141 / 2 39 14 71
Königsallee 43   |  Fax  : +49 3222 / 1 47 63 00 
71638 Ludwigsburg|  Mobil: +49  151 / 50 60 78 64
 |  WWW  :  http://www.rainboxx.de

CPAN: http://search.cpan.org/~mdietrich/
XING: https://www.xing.com/profile/Matthias_Dietrich18
GULP: http://www.gulp.de/profil/rainboxx.html





___
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] Re: DBI handle without "magic" when calling with dump_info=1 after updating Catalyst::Runtime

2010-11-23 Thread Matthias Dietrich
Hi Jeremy,

I cc'ed the list again so they all can see that we discuss about this :-).

Am 23.11.2010 um 14:13 schrieb Jeremy Dack:

> The problem seems to be with RenderView, do you use any custom views like
> JSON or is all your output HTML?

I use some other views than HTML in some apps, but this issue only occurs when 
HTML (here: Mason) should be printed.  AFAIK it also occurs when only a 
HTML/Mason view is available.

Matt

-- 
rainboxx Software Engineering
Matthias Dietrich

rainboxx Matthias Dietrich   |  Phone: +49 7141 / 2 39 14 71
Königsallee 43   |  Fax  : +49 3222 / 1 47 63 00 
71638 Ludwigsburg|  Mobil: +49  151 / 50 60 78 64
 |  WWW  :  http://www.rainboxx.de

CPAN: http://search.cpan.org/~mdietrich/
XING: https://www.xing.com/profile/Matthias_Dietrich18
GULP: http://www.gulp.de/profil/rainboxx.html





___
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] Re: DBI handle without "magic" when calling with dump_info=1 after updating Catalyst::Runtime

2010-11-23 Thread Matthias Dietrich
Hi Jeremy,

Am 23.11.2010 um 09:55 schrieb Jeremy Dack:

> Did you ever find a solution to the problem below as I’ve started to get the 
> exact same issue on my windows box?

I'm sorry I haven't and I'm still living with that issue.  Maybe the list could 
help?


> Re: DBI handle without "magic" when calling with dump_info=1 after updating 
> Catalyst::Runtime [In reply to]
> 
> Hi list, 
> 
> does someone knows anything about this error? As it occurs on two of my 
> systems (Linux, Mac) and at least on one unknown I heard of this seems not to 
> be an error of my local installation. 
> 
> Here's my error description as of 24.08.2009: 
> 
>> Hi, 
>> 
>> yesterday I've updated Catalyst::Runtime to 5.80011 and also did an update 
>> to several other modules (like Moose, DBIC, DBI and some plugins). Today I 
>> discovered that my DBI handle looses his "magic" when I call my app with 
>> parameter dump_info set to 1. This is the message printed on my console 
>> (current lates Mac OS X): 
>> 
>> $ sudo ./script/myapp_server.pl -p 80 -r 
>> You can connect to your server at http://rainboxx-pro.local 
>> SV = RV(0x24ae020) at 0x2501e60 
>> REFCNT = 1 
>> FLAGS = (ROK,READONLY) 
>> RV = 0x24f5f0c 
>> (in cleanup) dbih_getcom handle DBI::db=HASH(0x24f5f0c) is not a DBI handle 
>> (has no magic) at 
>> /opt/local/lib/perl5/site_perl/5.8.9/Data/Visitor/Callback.pm line 97. 
>> 
>> Each following request results in blank pages with exceptions in the log 
>> like: 
>> 
>> Can't call method "resultset" without a package or object reference at 
>> /opt/local/lib/perl5/site_perl/5.8.9/DBIx/Class/Schema.pm line 548. 
>> 
>> I need to restart the server to use it again. 
>> 
>> The error occurs everytime I'm surfing on my app and using dump_info then. 
>> If I restart the server and use dump_info with the first request, everthing 
>> is fine. If I access a normal controller page and use dump_info after that, 
>> the server goes down again. 
>> 
>> Do I need to update another module? Or is this a bug and if yes, of which 
>> module? Tell me how I can help to find this error. 
>> 
>> Thanks, 
>> matt 
>> 
>> P.S.: Although this seems to be as a question that should go to the DBIC 
>> list, I guess it is Catalyst related... 

Thanks

-- 
rainboxx Software Engineering
Matthias Dietrich

rainboxx Matthias Dietrich   |  Phone: +49 7141 / 2 39 14 71
Königsallee 43   |  Fax  : +49 3222 / 1 47 63 00 
71638 Ludwigsburg|  Mobil: +49  151 / 50 60 78 64
 |  WWW  :  http://www.rainboxx.de

CPAN: http://search.cpan.org/~mdietrich/
XING: https://www.xing.com/profile/Matthias_Dietrich18
GULP: http://www.gulp.de/profil/rainboxx.html





___
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-23 Thread Martin Bendix
- Original Message 

> From: Eden Cardim 
> To: The elegant MVC web framework 
> Sent: Tue, 23 November, 2010 0:59:18
> Subject: Re: [Catalyst] Begginer's question about application structure
> 
> > "Martin" == Martin Bendix   writes:
> 
> Martin> My model should be well separated from  the controller.
> Martin> Most, if not all of the application  functionality should be
> Martin> exposed via the model, so  that the Catalyst controller only
> Martin> needs to make  simple calls to the model.  To do this, model
> Martin>  classes should be created in 'lib/myapp', with simple
>  Martin> adapters in 'lib/myapp/Model', using
> Martin>  Catalyst::Model::Adaptor.
> 
> Controllers need to act as an adaptor between  the model and the
> view. So, for instance, mapping $cd->artist into a value  that's suitable
> for placing in a form field "value" attribute is the  responsibility of
> the controller (cos' when you change the UI into a CLI  switchboard, for
> instance, the mapping is going to be  different).
> 
> Martin> At this point, I am a little less  clear on how best to structure 
>my application.
> 
> Martin>  As my models will be primarily concerned with accessing the 
>database, how much 
>
> Martin> database code should go in my model classes, and  how much in the 
> Martin> DBIx::Class::ResultSet  classes?  For example, should I write a 
>method in my 
>
>  Martin> DBIx::Class::ResultSet classes that can add new CDs when 
> supplied  
>with title, 
>
> Martin> artist and a track list?  Or would  it be better to put this in 
> my 
>model?
> 
> You need to constrict the scope of  your methods as much as
> possible. That is, try not to write any code that  makes the ResultSet
> aware that it's being used in a web application. I find  that most of
> DBIC's API is well suited for being invoked directly by  the
> controller. You just need to avoid any constructs that make  the
> controller aware that there's actually a relational database behind  the
> model, because then you're free to swap out to an  alternative
> implementation. A general rule of thumb is to try to avoid  writing
> complex ->search methods in the controller, put those behind  a
> friendlier method on the ResultSet, for instance write a  resultset
> method that allows you to write $cds->released('this year')  (which you
> can implement via DatetimeX::Easy) instead of
> $cds->search({  'YEAR(me.date)' => DateTime->now->year }).
> 
>  Martin> Data validation could be handled by HTML::FormHandler, but
>  Martin> any validation performed here won't be of much use if  I
> Martin> later provide an alternative interface to my  application.  I
> Martin> assume that I should therefore  delegate validation to my
> Martin> model as well, so that the  same validation methods can be
> Martin> used no matter what  the interface?
> 
> I'm of the opinion that using form generators puts you  through the same
> amount of trouble than writing/validating forms by hand, so  I just dodge
> the HTML::FormHandler thing altogether, but that's just me,  YMMV.
> 
> -- 
>  Eden Cardim Need help with your perl Catalyst or DBIx::Class 
>project?
> Software Engineer  http://www.shadowcat.co.uk/catalyst/
>  Shadowcat Systems Ltd. Want a managed development or deployment 
>platform?
> http://blog.edencardim.comhttp://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/
>

Hi Eden,

Thank you for your reply.  It's good to know that so far I have been thinking 
along the right lines.

I've received some great advice so far, and your post is no exception.  
DatetimeX::Easy looks like another very useful module to add to the collection 
- 
yet another example of the wonders of Perl and its great community :-)



Regards,

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/