Re: [Catalyst] Catalyst Hosting

2007-08-09 Thread Brian Kirkbride

J. Shirley wrote:

If you want to take the VPS route now, I've been really happy with
Linode.com.  $20/mo and it's been rock solid for a couple months.
Have 2 slices and been very pleased.  Supportive IRC channel, plus a
responsive customer support system.

-J




Linode++

I used them for years before outgrowing it and moving on to several 
dedicated servers.  Their support cannot be beat and the prices are 
very reasonable.


Best,
Brian Kirkbride

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


Re: [Catalyst] Custom error

2007-06-27 Thread Brian Kirkbride

Jason Kohles wrote:


On Jun 26, 2007, at 12:45 PM, Brian Kirkbride wrote:


Jason Kohles wrote:

On Jun 25, 2007, at 1:27 PM, Evaldas Imbrasas wrote:

Yes, that's what I meant, thanks Brian. Please provide a code example
using RenderView action. I think it would also make sense to
incorporate that example into the Catalyst cookbook instead of
existing one since that one's incomplete.

Something like this...
sub render : ActionClass('RenderView') { }
sub end : Private {


Or even this:

sub render : ActionClass('RenderView') {}
sub end : Private {
  my ($self,$c) = @_;
  $c-forward('render');
  if (my @errors = @{$c-errors}) {
$c-errors(0);
$c-stash-{template} = 'error.tt';
$c-stash-{errors} = [EMAIL PROTECTED];
$c-forward($c-view('TT'));
  }
}

To allow for a templated error page.

The original question was how to deal with the view failing.  If your 
view is

broken, you probably don't want to try and use it to render the error...



If the error in the View is that the template was not found, or that 
it had a syntax error, you can render a templatized error page with no 
problem.


Point taken though, the proper solution is probably to try the View's 
error page, catch any errors and fallback to your original solution.


Best,
Brian

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


Re: [Catalyst] RFC for handling reverse proxies not deployed to standard ports.

2007-06-15 Thread Brian Kirkbride

Marlon Bailey wrote:

Current situation:  There is no clean solution for deploying a reverse
proxy to a nonstandard HTTP(80)/HTTPs(443) port, like port 8080.

Suggestion:  I'd like to submit a solution that extends the current
proxy-backend practice of reading the proxy values out of the request
header.  Currently the client's IP is taken from a X-Forwarded-For
header value, and the host's(Reverse Proxy) hostname is taken from a
X-Forwarded-Host header value. I suggest adding the ability for
Catalyst to set the host's port from a X-Forwarded-Host-Port header
value.  This way a simple config option such as this 


HEADER balancer_for_dev2 insert X-Forwarded-Host-Port: 8080

in a Perlbal config will give a clean solution.

Extras considerations:  After speaking with Matt(mst) about this, he
also suggested allowing the Path value to be set from a header value
as well.

What do you guys think?


I think that this would be great and give a lot more flexibility when 
deploying a proxied or load-balanced setup.  Especially the Path 
part, which would allow for the sort of sites within an app situation 
that I had asked about earlier.


The question is, would the X-Forwarded-Path header be the exact path 
Catalyst uses or would there be a X-Forwarded-Base header or somesuch?


Best,
Brian Kirkbride

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


Re: [Catalyst] Mapping another site to a subset of a Catalyst application

2007-06-07 Thread Brian Kirkbride

Brian Kirkbride wrote:

Hello all,

I've got an Catalyst webapp that has several areas:

/admin/...
/manage/...
/client/...

All of these are accessible from one site:

mysite.com/admin
mysite.com/manage
mysite.com/client

Now, here's the tricky part.  I'd really like to have a proxy or
URL-rewriting setup that allowed for:

client1.com/abc (handled by /client/abc)
client2.com/abc (handled by /client/abc)
client3.com/xyz (handled by /client/xyz)

I'm currently using FastCGI and it's not a problem to map multiple
virtual hosts to the Catalyst app.  I can even setup Apache to do
an Alias / /path/to/myapp_fastcgi.pl/client/, which starts to do what
I want.  The problem is that $c-uri_for will always return something
like http://client1.com/client/... for any action I need the URI to.

I'm sure there is a better way to do this?  I suppose that I could
override uri_for() to strip ^/client if the HTTP_HOST is not
mysite.com but that seems ugly.

Thanks in advance!

Best,
Brian Kirkbride


Replying to myself, comments welcome.

I've got a suitable workaround hacked up right now with the follow 
code in MyApp.pm:


sub prepare_action {
  my $c = shift;

  my $host = $c-req-uri-host;
  if ($host !~ /^mysite\.com$/i) {
$c-{_client_site} = 1;
my $path = $c-req-uri-path;
if ($path !~ /^clients/) {
  $c-req-path(clients$path);
}
  }

  return $c-next::method(@_);
}

sub uri_for {
  my $c = shift;
  my $uri = $c-next::method(@_);

  if ($c-{_client_site}) {
(my $path = $uri-path) =~ s|^/clients||;
$uri-path($path);
  }
  return $uri;
}


My first thought is that this prevents the app from having a base URI 
other than /, but that could probably be fixed with some clever 
$c-req-base checks in the regexes.


Am I missing anything important?  Something that might come back to 
haunt me later on?


Thanks!
- Brian

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


[Catalyst] Handling slow uploads externally

2007-04-12 Thread Brian Kirkbride

Hello all,

I have a CMS-like application using Catalyst for which about 40-50% of requests 
contain large file uploads.  I'm using a pretty standard two-tiered setup to 
avoid tying up heavy mod_perl procs for slow client downloads.


Now I'd like to avoid tying up the heavy procs for slow uploads.  Many suggest 
to run upload handlers as CGI rather than mod_perl because the 1s startup time 
is negligent compared to the time required to upload.  I have tried this and it 
works, but it still creates a 60+ MB process to sit around for 2 minutes while a 
dial up user uploads a huge image.


I'm thinking of splitting file upload handling out to a simple CGI app (no 
Catalyst code) that serializes the request, including uploaded files, to a tmp 
directory.  It would then redirect to a Catalyst-handled URL matching the 
serialized request.  Then I can validate the submission in Catalyst and display 
success or error using my views, etc.


Is there something like this in existence already?  I searched Google and CPAN 
but didn't find anything promising.  I'd appreciate any tips or suggestions.  If 
I do implement it from scratch, would there be any interest in the CGI and a 
Catalyst base controller being released on CPAN?


Best,
Brian Kirkbride

___
List: [EMAIL PROTECTED]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Handling slow uploads externally

2007-04-12 Thread Brian Kirkbride

Perrin Harkins wrote:

On 4/12/07, Brian Kirkbride [EMAIL PROTECTED] wrote:
Now I'd like to avoid tying up the heavy procs for slow uploads.  Many 
suggest
to run upload handlers as CGI rather than mod_perl because the 1s 
startup time
is negligent compared to the time required to upload.  I have tried 
this and it
works, but it still creates a 60+ MB process to sit around for 2 
minutes while a

dial up user uploads a huge image.


Yeah, I was reading that and thinking that you'll probably use more
memory for CGI, since you still have to run perl but you don't get any
copy-on-write benefit.  It could be offset by loading as few modules
as possible into the CGI, but that seems kind of ugly.

A better solution would be a proxy that buffers uploads.  I thought
mod_proxy would do this for you.  Are you certain that it doesn't?  If
so, take a look at the other proxy options out there.

- Perrin


Perrin,

It doesn't look like mod_proxy, which I am currently using, supports this.  It 
looks like Perlbal does however.  Any other suggestions?  I'd like to avoid 
Squid as it would be overkill for this application.


Thanks!

___
List: [EMAIL PROTECTED]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Re: Handling slow uploads externally

2007-04-12 Thread Brian Kirkbride

A. Pagaltzis wrote:

Hi Brian,

* Brian Kirkbride [EMAIL PROTECTED] [2007-04-12 19:25]:

I have a CMS-like application using Catalyst for which about
40-50% of requests contain large file uploads. I'm using a
pretty standard two-tiered setup to avoid tying up heavy
mod_perl procs for slow client downloads.

[…]

I'm thinking of splitting file upload handling out to a
simple CGI app (no Catalyst code) that serializes the request,
including uploaded files, to a tmp directory. It would then
redirect to a Catalyst-handled URL matching the serialized
request.


My suggestion is to do something much more transparent.

Use a CGI script on the front-end webserver to accept uploads.
When the upload completes, the CGI script then in turn makes a
HTTP request to the application webserver server to upload the
file, and returns the app’s response to the client.

That way, the actual application itself does not need to change
at all. There is no serialisation mechanism, no extra code in the
application to handle such a special upload mechanism, no need
for configuration of filesystem paths or other shared resources,
nothing. The handling is isolated on the front-end webserver.

This way, a programming consideration becomes a mere deployment
consideration.

HTTP is great like that.


Is there something like this in existence already? I searched
Google and CPAN but didn't find anything promising. I'd
appreciate any tips or suggestions. If I do implement it from
scratch, would there be any interest in the CGI and a Catalyst
base controller being released on CPAN?


Sometimes, there is no code to do something because no code is
needed to do it. :-)



Wonderful, thank you for the insight Aristotle.  I will try Perrin's suggestion 
of using an upload-buffering proxy first, falling back on a simple CGI proxy 
like this if need be.


___
List: [EMAIL PROTECTED]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Root.pm $c-detach() does not detach?

2007-04-03 Thread Brian Kirkbride

Luis Azevedo wrote:

Hi All,

In Root.pm, auto action I am trying to break the execution of chain of 
Actions.


To be more exact, whenever I detect I loose connection to a socket or cookie 
session, I want to redirect the user to a login action, not rendering the 
action the user is calling.


I know I can make a simple $c-res-redirect() but the problem is I need to 
show a message in the login page telling the reason for the logout. Usually 
I am passing messages trough Stash. Redirecting to the Login page needs to 
pass message somehow (through GET or POST, therefore not so beautiful s).


I have tried to detach the /login action,  in auto action from Root.pm 
controller,  but it is not working and I don't know why. See the actions 
chain:
| /auto  
|  - /login/index   
| /about/index   
| /end   


The user called the /about action.

Can I break the chain somehow in Root.pm, auto action?

Thanks in advance,




I think what you want is something like

if (!$logged_in) {
$c-action(undef);
$c-detach('/login');
}

Setting the action to undef in an auto sub will prevent the normal dispatch of 
the request.


Best,
Brian

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


Re: [Catalyst] Catalyst::Model::DBIC::Schema or not?

2007-03-28 Thread Brian Kirkbride

Jason Gottshall wrote:

Brian Kirkbride wrote:

I definitely have Models, but they are a higher-level abstraction than
the ORM 

layer.  If I understand your argument, you are advocating that data
constraints 

imposed by your business logic be enforced by the the DB rather than
the ORM. 

That's all fine and good, but MUCH lower level than what I have in my
Catalyst 

Models.

I usually have an architecture like this:

Client - Controller - Model - ORM - Database

The ORM is usually just vanilla (as you suggested), the Database
enforces simple 

data constraints (foreign keys, etc) and the Model makes sure that the
complex 

business logic constraints are met.  Some things are simply not
enforceable by a 

stored procedure - this might involve validation of image files for

example.

The beauty of Catalyst is that it's up to you how to handle separation
of 

concerns and Catalyst is helpful no matter how you do.


Thanks, Brian. This is the exact structure I'm considering. So my
question is this: If all the ORM interaction happens at the Model level,
and DBIC isn't being treated as a model itself, is there any reason to
use Catalyst::Model::DBIC::Schema to establish the db connections? I
guess my gut tells me no, but I want to make sure I'm not missing
something here.



No problem.  As I said in my earlier reply, I don't have DBIC models in my 
catalyst app because it encourages me to put ORM-related code where it belongs, 
in the Business Logic model(s).


Best,
Brian

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


Re: [Catalyst] Catalyst::Model::DBIC::Schema or not?

2007-03-23 Thread Brian Kirkbride

Jason Gottshall wrote:

Catalysters:

I'm developing a new app using Catalyst, with DBIC as the db persistence
layer. I intend to build Models that encapsulate the business logic and
that will use DBIC to interact with the database as necessary, instead
of using DBIC as a model itself.

So if I'm not using DBIC from the controller directly, is there any
reason for me to use Catalyst::Model::DBIC::Schema? It seems like I'm
just adding an unnecessary layer of code.

Comments from any of you who have a similar setup would be especially
welcome.

Jason




I only have Model classes for my business logic and have never had a problem 
with that.  A bonus is that it forces you to say:


   $c-model('MyLogic')-_get_schema-resultset('Users')

instead of:

   $c-model('Schema::Users')

and that makes you think about ugly hacks that circumvent your business logic.

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


[Catalyst] RFC: Chained actions with PathPart('.')

2007-03-22 Thread Brian Kirkbride

Hello all,

I've been working with Chained actions, and like many others have found them to 
be incredibly useful for setting up DBIC result sets before reaching an endpoint.


The one thing that has been bothering me is that to start a chain in some 
controller, say MyApp::C::Admin::Services you would need to declare:


  sub get_id : Chained('/') : PathPart('/admin/services') : CaptureArgs(1) {
  # stash the id or do some lookup
  }

It's most likely my ignorance showing, but this seems redundant and not very 
DRY.  That's why I'd suggest that PathPart('.') set a chained action's PathPart 
to the namespace on the controller.  That way you could simply do:


  sub get_id : Chained('/') : PathPart('.') : CaptureArgs(1) {}

Renaming controllers or moving the action to a new controller automatically 
updates the leading path to the start of the chain.  I assume that this would 
only make sense if the Chained attribute is '/'


I've attached a patch implementing this change, comments or criticisms much 
appreciated.


Best,
Brian Kirkbride
--- /tmp/Chained.pm 2007-03-22 13:27:35.452477260 -0500
+++ /opt/catalyst/lib/Catalyst/DispatchType/Chained.pm  2007-03-22 13:41:26.697583229 -0500
@@ -228,6 +228,15 @@
 );
 }
 
+   if ($part eq '.') {
+   unless ($parent eq '/') {
+   Catalyst::Exception-throw(
+   PathPart of '.' requires Chained('/') registering ${action}
+   );
+   }
+   $part = $action-namespace;
+   }
+
 $action-attributes-{PartPath} = [ $part ];
 
 unshift(@{ $children-{$part} ||= [] }, $action);
___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] RFC: Chained actions with PathPart('.')

2007-03-22 Thread Brian Kirkbride

Brian Cassidy wrote:
Perhaps you're looking for PathPrefix (coming to a new Catalyst near you 
... eventually -- it's in svn now.). For now, do this:


sub _parse_PathPrefix_attr {
my ( $self, $c, $name, $value ) = @_;
return PathPart = $self-path_prefix;
}

sub get_id : Chained('/') PathPrefix CaptureArgs(1) { }

You can put the _parse_PathPrefix_attr sub in a base controller and 
all of your controllers will have access to it.


-Brian



Cheers!

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


Re: [Catalyst] Form Module Dichotomy

2007-03-22 Thread Brian Kirkbride

Alejandro Imass wrote:

Hello,

I wrote a complete backend in HTML::Widget a couple of months ago, and
now I'm adding new functionallity to another part of the site. The
question is:

a - Stick with HTML::Widget and wait for FormFu ?
b - use C::C::FormBuilder ?

I am inclined for option b, but would like some feedback from others
before going down this path.

Thanks in advance for any comments.

Alejandro


I'm in exactly the same bind and given everything I've seen of FormFu, I'm 
definitely opting for (a).  Not to knock FormBuilder at all, people seem to 
swear by it but I've not had time to explore it much.


To me it seems that Carl has really designed FormFu to be like HTML::Widget 
but with many lessons learned.


Best,
Brian

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


Re: [Catalyst] Re: Announce: Website In A Box

2007-03-21 Thread Brian Kirkbride

Thomas Klausner wrote:

Hi!

On Wed, Mar 21, 2007 at 04:47:15PM -0400, Christopher H. Laco wrote:
 

Or more to the point... have app supplied templates, and be able to user
user customized templates in combination with the app
templates...without have to worry about sources, merging, upgrade, etc...


I usually (using TT) do something like:

INCLUDE_PATH: [base_framework_stuff app_stuff]

All the templates go into base_framework_stuff
All modifications needed for an app (or maybe even a sub-area of an app) 
go into app_stuff.


You just need to break your templates into enough smallish components. 
In the end, it feels a lot like OO templates, where you can override 
the base implementation.





I'm glad to see someone else doing this!  I've found it works well for my 
projects and does feel very OO indeed.  As Thomas said, it is mostly about 
finding the right granularity.  Not so small as to make it hard to understand a 
template's function at a glance, but small enough that an override wouldn't step 
on something you plan to update in a new revision.


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


Re: [Catalyst] Re: Announce: Website In A Box

2007-03-21 Thread Brian Kirkbride

Christopher H. Laco wrote:

THe only part of that that feels dirty is that it's still an either-or
situation, rather than an base_mine situation. That could be solved by
TT plugins, but that's nasty at some level.


True, but if you get the granularity right this is not a problem.  Think of 
method overriding as a metaphor:


Class A
- method outer (calls inner)
- method inner (calls detail)
- method detail

Class B
- method inner
(inherits outer and detail)

can be compared to:

templates/base/
  outer.tt2 (PROCESS inner.tt2)
  inner.tt2 (PROCESS detail.tt2)
  detail.tt2

templates/local/
  inner.tt2

Hopefully that makes sense!

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


Re: [Catalyst] Regex -- optional index.html

2007-03-02 Thread Brian Kirkbride

Michael Reece wrote:

i don't think it's a bug.



snip


have you tried adding :Args(0) to the action?


That was my guess too, I've been bit by this problem before adding Args(0) to my 
actions.


- Brian

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


Re: [Catalyst] Re: memory usage of mod_perl process

2007-02-08 Thread Brian Kirkbride

Jeffrey Ng wrote:
I am the coworker of Fayland who posted the topic memory usage of 
mod_perl process.


Our company has invested quite some time on migrating our perl code to 
catalyst (more than half year of time by 7 programmers). However, I am 
starting to worry that moving to catalyst is causing too much overhead 
for our processes and thus severely slowing down our site.


I remember the memory usage of each process before catalyst was around 
25Mb. And now the new code is using around 90MB as fayland said. During 
peak hour, our servers were able to handle 30+ requests per sec before 
catalyst upgrade. Now we are only able to handle around 10 requests per 
sec.


As a result, the response time of the site is much slower after the 
upgrade. it takes at least 2 sec for the browser to start responding 
during non-peak hours.


Here's the memory stats for a typical process:

Memory Usage (in bytes):

  Size   :   97107968 (92.6M)
  Share  :6012928 ( 5.7M)
  VSize  :   97107968 (92.6M)
  RSS:   85131264 (81.2M)

Memory Segments Usage (in bytes):


  Text   : 253952 ( 248K)
  Shlib  :  0 (   0K)
  Data   :   78696448 (75.1M)
  Stack  :  0 (   0K)



I have read practical mod_perl. I tried to preload many of our modules 
in startup.pl. But the shared memory value doesnt change at all. Also, 
doesnt 5.7M shared memory usage sound too small comparing to the 92.6M 
total size?


I wonder how much is your shared memory? Is the memory overhead of 
catalyst huge? Is catalyst inherently slow?




I too have found that my Catalyst apps are huge compared to previous mod_perl 
or FastCGI apps.  I had been using Class::DBI and a hand-rolled framework, but 
now use Catalyst and DBIx::Class.  The difference is at least a factor of 2.


It's not been a problem for me at my current traffic levels, and I'm more than 
happy to trade some RAM for the joy the design and coding has become compared to 
my previous situation.


But I do wonder where all the RAM is going.  I especially concur that not much 
is being shared which is curious given that the modules are preloaded by 
mod_perl.  I had done some profiling to measure how much RAM a dummy Cat app 
took vs a dummy DBIC schema, maybe I'll dig that up and send it to the list.


Best,
Brian

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


Re: [Catalyst] Accessing action URIs outside of Catalyst app

2007-01-08 Thread Brian Kirkbride

Matt S Trout wrote:


On 3 Jan 2007, at 20:21, Brian Kirkbride wrote:


Hello all,

Is there a best practice way to maintain a map of URLs used in a 
Catalyst application.  To clarify, I need to map actions to URLs 
outside of Catalyst (CRON jobs, Emailers, etc) and won't have access 
to $c-uri_for or the $c-dispatcher.


If you need to do this, your design is broken.


Perhaps, but I ascribe that to it being in transition :)



Step back. Explain what you're trying to achieve.


Automated emails sent out to users need to provide them with a list of different 
webapp URLs.  These actions are asynchronous from the webapp itself.  I have a 
number of scripts (a few are legacy dinosaurs) that need webapp URLs as well.


If I choose to change /cancel to /account/cancel later on, I'd like to do it in 
one place.  I realize that without parsing the controllers' actions I can't 
expect the outside code to get those URLs.  I would also rather not use 
MyApp.pm in simple scripts that only need my model logic and a URL, and in some 
cases I can't.


My hope was to configure the URL mapping in a config file, which could be 
accessed by my webapp and outside scripts.  Something like this:


sub cancel : Args(1) : Path($urlmap-{account_cancel}) {
# action
}

This, of course, does not work because attributes do not evaluate their 
arguments.  Perhaps my solution is to subclass the Dispatcher to allow for:


sub cancel : Args(1) : FromURLMap('account_cancel') {
# action
}

That wouldn't be too hard.  Thoughts?

Best,
Brian

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


Re: [Catalyst] iterating twice over the same resultset in the template?

2007-01-03 Thread Brian Kirkbride

Fernan Aguero wrote:

[ or perhaps 'is it possible to clone a resultset?' ]

Hi!

I'm building a form whose elements are items taken from the
db.  And I need these items to show up in different elements
(fieldsets) of the form. More or less something like this:

With items similar to:
 'checkbox' - Item 1
 'checkbox' - Item 2
 'checkbox' - Item 3

with parts that belong to:
 'checkbox' - Item 1
 'checkbox' - Item 2
 'checkbox' - Item 3


In my controller:
my $rs = $model-search( ... );
$c-stash-{items} = $rs;

In my template (TT):
form ...
fieldset
[% WHILE ( it = items.next() ) -%]
input ...  [% it.name -%]
[% END -%]
/fieldset

fieldset
[% WHILE ( it = items.next() ) -%]
input ...  [% it.name -%]
[% END -%]
/fieldset
/form

The problem is that the resultset is empty when I try to
iterate over it the second time. 


So far the only way I've found to make this work is
to do N separate searches, fill N stash elements, et cetera 


$rs1 = $model-search( ... ); $c-stash-{rs1} = $rs1;
$rs2 = $model-search( ... ); $c-stash-{rs2} = $rs2;
...

[% WHILE ( it = rs1.next() ) -%] ...
[% WHILE ( it = rs2.next() ) -%] ...

Is there any other way to do this? Is it possible to clone a
resultset?

Thanks,

Fernan



You want rs.reset() between the iterations IIRC.

Best,
Brian

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


[Catalyst] Accessing action URIs outside of Catalyst app

2007-01-03 Thread Brian Kirkbride

Hello all,

Is there a best practice way to maintain a map of URLs used in a Catalyst 
application.  To clarify, I need to map actions to URLs outside of Catalyst 
(CRON jobs, Emailers, etc) and won't have access to $c-uri_for or the 
$c-dispatcher.


Right now I have a hashref of action_name = relative_url with a $APP_ROOT_URL 
constant defined in my general-purpose/non-cat modules.  This is ugly and I have 
to manually sync the actions in my controllers with the hash.


Best,
Brian

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


Re: [Catalyst] system() within Catalyst

2006-10-18 Thread Brian Kirkbride
Brandon Maust wrote:
 Hi. 
 
 I'm trying to use Chart::Graph::Gnuplot to generate some images inside 
 of one of my application's Views.  That module uses system() to run 
 gnuplot and checks the return status like so, as described in the 
 system() documentation:
 
 $exit_value  = $?  8;
 $signal_num  = $?  127;
 $dumped_core = $?  128;
 
 
 My problem is that while gnuplot (and several other commands such as 
 touch and cat) seem to run successfully, perl sees a non-zero exit code 
 within Catalyst.  Running the same code in a straight perl script 
 provides the expected results.
 
 Is this a known effect?  Aside from editing the source for this module, 
 I can't find a good workaround to use it.
 
 Thanks for any suggestions,
 Brandon
 

This is a known issue when running under the dev HTTP server included with 
Catalyst.   My solution has been to wrap the system() call inside a block with 
a 
default SIGCHLD handler like so:

{
local $SIG{CHLD} = 'DEFAULT';
system(@args);
if ($?) {
die Failed: $?\n;
}
}

This is related to the Restarter code in Catalyst::Engine::HTTP.  I had started 
to see if the signal handler could be reset to the default in the forked child 
process to avoid this problem, but didn't have the time to fix it.  I only use 
system() in 1 or 2 places and the local fix was acceptable for me.

Best,
Brian Kirkbride

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


Re: [Catalyst] Dynamically adding ActionClass

2006-10-06 Thread Brian Kirkbride
Juan Camacho wrote:
 I have an existing catalyst plugin where I would like to set a stash
 item after the Controller is called but before the View is executed.
 One way of doing this is by simply creating a custom ActionClass that
 sets the stash item.  Is there a way to dynamically add an ActionClass
 from within the plugin code? I want to avoid adding instructions for
 existing plugin users to write sub foo : ActionClass('Bar') in their
 controllers, and breaking backward compatability.
 
 Besides the ActionClass approach is there another way to do this?
 
 Juan
 


This might be another case that would benefit from the end-time auto feature 
that has been discussed before.  Since we have begin/end, I would favor an 
auto/post_auto as well.  Any better name suggestions? :)

Best,
Brian Kirkbride

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


Re: [Catalyst] Recommendation For Logging To A File

2006-09-24 Thread Brian Kirkbride
Bill Moseley wrote:
 On Sun, Sep 24, 2006 at 02:32:52PM -0400, [EMAIL PROTECTED] wrote:
 What is the recommended best way (or the 2-3 top contenders if there
 is no one best way) to have a Catalyst app log in production to a
 file (at least I assume that's what most people want their production
 apps to do).  Is Catalyst::Log::Log4perl the way to go?
 
 I just find that the normal error logs and grep or perl get me most
 of what I need.
 
 I have $c-info and $c-error and those are just wrappers for
 $c-log-info and $c-log-error that tack on the IP, current user,
 and a few other bits of common data I find useful when reading th
 logs.  Those go to stderr and apache writes those to the error log
 and is rotated with logrotate.
 

I used to do the same, but now that I'm running my Cat app under FastCGI 
everything is prefixed in the apache logs with mod_fastcgi: [stderr] blah blah 
which is a serious pain.  Anyone know how to prevent the prefixing?

I'm using (Catalyst::)Log::Log4perl nowadays and it seems fine.  I don't really 
use much more than a single File appender and a formatted layout.  In the 
future 
it might be nice to filter errors and warnings to different logs/emails.  At 
least I know that I can do that later with a simple log4perl.conf config file 
change.

Best,
Brian Kirkbride

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


Re: [Catalyst] Catalyst::View::TT - strange caching annoyance

2006-09-13 Thread Brian Kirkbride
Jonathan Rockway wrote:
 Good find.  The whole complicated [% BLOCK %] business that I was
 complaining about was actually the problem.  I admit to never having
 used [% BLOCK %], so that's why I didn't run into the problem.
 
 Regards,
 Jonathan Rockway
 

Ah, that makes sense.

What do you usually do in stead of using BLOCK?  Do you put anything that will 
be INCLUDEd or PROCESSed into separate files?  I tend to put all related small 
chunks of HTML, Javascript, etc into separate, named BLOCKs in a single .tt2 
file.  And for anything I'll be using on a regular basis, I make them MACROs 
instead.

Cheers,
Brian

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


Re: [Catalyst] ways to do stuff and why

2006-08-21 Thread Brian Kirkbride
Mark Blythe wrote:
 If the controller truly never sees DBIC stuff, does that mean that
 your model logic never returns DBIC objects?  For instance, let's say
 you have a logic method called findBestFit() that's supposed to return
 shoes that fit a given person and activity the best.  Would it return
 a DBIC ResultSet made up of Shoe row objects, or would findBestFit()
 deal with those objects only internally and construct something
 non-DBIC for the return?
 
 That's a choice I struggled with up front, and I finally decided that
 sticking with DBIC objects made better sense for me than inventing a
 whole new layer simply to abstract them and provide similar but not
 DBIC-specific interfaces.
 

I'm right there with you - I want to abstract but without reinventing the wheel.

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


Re: [Catalyst] ways to do stuff and why

2006-08-18 Thread Brian Kirkbride
[EMAIL PROTECTED] wrote:
 Matt S Trout [EMAIL PROTECTED] on  08/18/2006 12:33 PM:
   Ek, not at all. The model should encapsulate *all* business logic 
 and
   similar - it should be a model of the domain with which the app 
 interacts. The
   Controller should be as thin a layer as possible whose sole purpose 
 is to
   arbitrate between the model's view of reality and the user interface 
 (i.e. the
   view)
 
 I disagree.
 
 In an MVC sense:
 The model is the data.
 The controller is the business logic.  
 The controller receives commands from the user interface, and 
 manipulates the models.
 The models are then displayed via views

This is what I had thought initially, but I have come to see the benefit of 
doing it the way Matt describes.

I have Catalyst and non-Catalyst web applications, CRON jobs and command-line 
utility scripts for my project.  They all need access to the data in the model, 
and that is provided by the ORM.  That can be accomplished in either your way 
or 
the logic-in-the-model way.

But many of the command-line tools need to do the same thing as a controller in 
the Catalyst application.  Sometimes the CRON jobs do too.  Since the code in 
the Catalyst controller is dependent on the Catalyst request life cycle, it's 
not in itself reusable.  I don't want Catalyst controllers calling the external 
scripts either.

At this point, if I want code reuse I have two reasonable choices:

A) Create business logic modules, ie. MyApp::Logic::CreateTrial, etc
B) Write my own business logic methods in MyApp::Schema::Trial-create(...)

Either is valid and from what I gather Java developers like the Logic route.  I 
chose (B) because I already have the classes and the logic is *usually* just 
operating on that class's data model.

I'm very interested in hearing others' thoughts on this, because it really 
seems 
to be a point of contention in MVC/Web programming.

Best,
Brian

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


Re: [Catalyst] ways to do stuff and why

2006-08-18 Thread Brian Kirkbride
[EMAIL PROTECTED] wrote:
 Brian Kirkbride [EMAIL PROTECTED] @ 08/18/2006 01:57 PM:
   At this point, if I want code reuse I have two reasonable choices:
  
   A) Create business logic modules, ie. MyApp::Logic::CreateTrial, etc
   B) Write my own business logic methods in 
 MyApp::Schema::Trial-create(...)
  
   Either is valid and from what I gather Java developers like the Logic 
 route.  I
   chose (B) because I already have the classes and the logic is 
 *usually* just
   operating on that class's data model.
 
 [Insert snarky Java comment here]
 
 B couples my business logic too tightly with the ORM. ORMs fall out of 
 fancy.
 The whole point of MVC is loose coupling. Method A does not have that 
 tight coupling.
 This is a bit of good advice I've picked up along the way:
  Loose coupling of objects.  Code to the abstract class (API) not 
 the implementation.
 
 Sometimes it helps to forget about ORM's for a minute.  The hash or 
 array of data returned
 by DBI is still your Model.  It you want objects, you have to roll your 
 own, around the DBI data.
 Roll your own around the DBIC data, use object composition, rather than 
 inheritance.  The coupling
 is looser, and that makes your code less brittle.
 

I'm leaning toward this as well, you might have convinced me with the 
composition argument.  I had been thinking of it in terms of inheriting from 
the 
model.

I've moved from a home-grown ORM to Class::DBI to DBIx::Class in this project's 
history.  The business logic methods in the model classes had to change each 
migration.  Not a big deal, because it usually changing -find to -retrieve or 
something that simple.

But not having to ever change a controller, script or CRON job by way of a set 
of Logic:: proxy classes would be nice.  Generally these bits don't have to 
know 
much of anything about the model implementation so it hasn't been much to 
change.  But when iterating over result sets it's hard to avoid the model 
implementation specifics.

Maybe I'll spend the weekend whipping up some proxy classes to sit between my 
model and the rest.  I that the business logic methods in the model would be 
moved into these classes as well.

Thanks!
- Brian

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


Re: [Catalyst] Sigh. How do we get on this list?

2006-08-09 Thread Brian Kirkbride
Simon Wilcox wrote:
 On Tue, 8 Aug 2006, Christopher H. Laco wrote:
 
 Make it really really easy to get started for people who don't know much
 perl.
 

Here we get into a tricky debate about ease-of-use vs flexibility and 
performance.  While not mutually exclusive, it is very difficult and sometimes 
impossible to achieve both.  Rails is easy because, it would appear, it 
sacrifices TMTOWTDI - they lost me right there.

The trick is to make the defaults work in an outrageously easy way, without 
handicapping developers that know what they are doing and need something more 
complex.  Not always possible and certainly not easy - but I find that Catalyst 
and DBIx::Class are achieving this more with each new release.

 Unfortunately (or fortunately depending on your point of view) Perl people
 generally mistrust marketing so Catalyst is unlikely to grow beyond the
 perl community. Some may say that's a good thing.
 

I'd rather have the design decisions for my chosen framework made in 
consideration of the pragmatic than the marketing side of things.  Might not 
get 
it in MacOS X and it might not get it at the top of ora.com, but it will make 
it 
the best.  That's what matters.

(I do realize that marketing and public perception get you grants and backing 
and funding and users, but those things can often be corrupting to original 
your 
goals)

Thanks again to the teams working on these two great projects!

- Brian

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