Re: [Catalyst] Duplicating a Catalyst app

2011-06-10 Thread Stephen Clouse
On Fri, Jun 10, 2011 at 4:21 PM, Bill Moseley  wrote:

> I have an app "Foo" and would like to make a new application based on it
> called "Bar".
>
> Is there a better approach than making a copy and s/Foo/Bar/g in most
> directories (lib, t)?


This is probably not a full solution, but may get you on the path to one.

I had a similar problem at $work where we have a core Catalyst application,
but also needed the ability to install customer-specific components (either
completely new functionality, or overriding one of the core controllers),
and didn't want this to turn into a management nightmare (like
hand-replacing specific component files on certain customers' systems and
praying we remembered when upgrading them later, which is what we
unfortunately did with our ancient CGI-script-based "app").

Our Catalyst implementation looks something like this:

package My::App;

use Moose;
use Catalyst;

__PACKAGE__->config(
customers => [qw/Initech/],
setup_components => {
except => qr/^My::App::(Controller|Model|View)::Customer::/,
},
);

around locate_components => sub {
my $orig  = shift;
my $class = shift;
my @comps = $class->$orig(@_);
foreach my $customer (@{$class->config->{customers}}) {
my @paths = qw( ::Controller ::Model ::View );
my $locator = Module::Pluggable::Object->new(
search_path => [ map {
s/^::(.*)/${class}::$1::Customer::${customer}/; $_; } @paths ],
);
foreach my $comp ($locator->plugins) {
my $replace_class = $comp;
$replace_class =~ s/::Customer::${customer}//;
@comps = grep {$_ ne $replace_class} @comps;
push @comps, $comp;
}
}
return @comps;
};

The code above roughly does the following:

   - Find all components as Catalyst normally does
   - For each customer identifier, search a customer-specific component tree
   (My::App::(C|M|V)::Customer::$cust)
   - For each component found there, append it to the list of components to
   load
   - If the customer-specific component shares its class path with a core
   component, remove the core component from the load list (i.e.,
   ::Controller::Customer::Initech::Foo causes ::Controller::Foo to be skipped;
   the assumption is that the customer-specific module extends it or replaces
   it entirely)

If I had to adapt your problem to my problem, the core application would be
Foo, and our customer would be Bar.

I hope this gives you some ideas.

-- 
Stephen Clouse 
___
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] Duplicating a Catalyst app

2011-06-10 Thread Bill Moseley
I have an app "Foo" and would like to make a new application based on it
called "Bar".

Bar will get a new design and templates, and will have many of the same
controller actions.  But, I expect over time the two apps will drift apart
in functionality.  Different people will maintain Foo and Bar apps.

Is there a better approach than making a copy and s/Foo/Bar/g in most
directories (lib, t)?

I first thought I'd pull out the controllers from the original Foo and turn
them into roles, and then just use the roles in both applications, but I'm
not sure we want to share code like for the risk of a change in one role is
not wanted in the other (and is missed by testing).

The other option, of course, is to keep one app and have it run with
different configurations and different "root" directory (so separate css,
js, templates, etc).  But, again, then have to think about how to manage
changes that only effect one app.

Suggestions?



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


[Catalyst] Re: REST-like url question

2011-06-10 Thread Aristotle Pagaltzis
* Bill Moseley  [2011-05-18 18:30]:
> And these seem wrong because the query parameter is about the
> user not the session.

Why do you care?

> That is, seems like any query parameters should be limiting on
> the session (e.g. session_type).
>
> GET /user/1234/sessions?user_type=attendee
> GET /user/1234/sessions?user_type=presenter
>
> Other options would be:
>
> GET /user/1234/sessions_attending
> GET /user/1234/sessions_presenting
>
> What would you use?

You are presenting a collection in all cases, and the list is the
same in all cases. You are just filtering it differently.

Use a query parameter.


* John Beppu  [2011-05-22 20:55]:
> Could you pull this off?
>
> GET /user/1234/sessions
> GET /user/1234/sessions/attending
> GET /user/1234/sessions/presenting
> GET /user/1234/sessions/attending+presenting
>
> This is similar to how del.icio.us handles tags.

Attending + presenting = all. The first and last of these URIs
mean the same thing.

Regards,
-- 
Aristotle Pagaltzis // 

___
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] [OT] Anybody else going to O'Reilly Velocity next week?

2011-06-10 Thread Larry Leszczynski
Hi all -

Just wondering if anybody else is planning to go to the O'Reilly
Velocity conference in Santa Clara next week - email me off-list and we
can make plans to meet up.


Thanks!
Larry

___
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] Semi-OT testing question

2011-06-10 Thread Jesse Sheidlower
On Fri, Jun 10, 2011 at 11:19:14AM -0400, Ronald J Kimball wrote:
> On Fri, Jun 10, 2011 at 11:10 AM, Jesse Sheidlower  wrote:
> 
> >
> > ok( $mech_admin->tick('roles','2'), "ticked the newwords_admin checkbox" );
> >
> 
> 
> > The only thing failing here is the _test_ in the first line of this. The
> > form is submitted correctly, and when I test the "view" page for this
> > newly-created user, it has the correct role.
> >
> > Similarly, for my "edit" test, I untick this role, tick a different
> > role, and the results are correct. But both "ok" tests for the unticking
> > and ticking, fail.
> >
> > What's wrong with my test here?
> >
> 
> WWW::Mechanize->tick() and WWW::Mechanize->untick() don't return anything on
> success.  They call WWW::Mechanize->warn() if the referenced checkbox does
> not exist.

Ah. That would indeed explain it then. Thanks!

___
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] Semi-OT testing question

2011-06-10 Thread Ronald J Kimball
On Fri, Jun 10, 2011 at 11:10 AM, Jesse Sheidlower  wrote:

>
> ok( $mech_admin->tick('roles','2'), "ticked the newwords_admin checkbox" );
>


> The only thing failing here is the _test_ in the first line of this. The
> form is submitted correctly, and when I test the "view" page for this
> newly-created user, it has the correct role.
>
> Similarly, for my "edit" test, I untick this role, tick a different
> role, and the results are correct. But both "ok" tests for the unticking
> and ticking, fail.
>
> What's wrong with my test here?
>

WWW::Mechanize->tick() and WWW::Mechanize->untick() don't return anything on
success.  They call WWW::Mechanize->warn() if the referenced checkbox does
not exist.

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/


[Catalyst] Semi-OT testing question

2011-06-10 Thread Jesse Sheidlower

I'm testing a Cat app using T::W::M::Catalyst, and am struggling to
understand why one test is failing. It's only the test that's failing;
the action is OK.

I have a simple add-user form that has several checkboxes for different
roles the user can have. I first tick the checkbox corresponding to the
role I want, and then use submit_form_ok with the rest of the info. (If
I can tick the box using submit_form_ok I'm happy to do so, but I can't
figure out how.)

---

ok( $mech_admin->tick('roles','2'), "ticked the newwords_admin checkbox" );

$mech_admin->submit_form_ok( { fields => {
  login => 'new_user',
  password => 'new_user',
  name => 'New Regular User',
  email => 'foo-...@bar.com'
}, }, "Submitted add-user form");

---

The only thing failing here is the _test_ in the first line of this. The
form is submitted correctly, and when I test the "view" page for this
newly-created user, it has the correct role.

Similarly, for my "edit" test, I untick this role, tick a different
role, and the results are correct. But both "ok" tests for the unticking
and ticking, fail.

What's wrong with my test here?

Thanks.

Jesse Sheidlower

___
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/