FAQ
Hi all,

I have a question regarding controller refactoring, and whether
subclassing (or adding a Moose role) would be a good idea for a
particular application.

The application creates 6 different types of invoices, each representing
a particular type of service. Currently, I have a controller for each
that handles the various steps that must be taken to produce and
ultimately send these invoices. ALL OF THESE CONTROLLERS HAVE THE SAME
ACTIONS, and most of the same logic, which to me says I should refactor
these controllers...I just don't know how, and also whether the benefit
is worth the work. Almost certainly it would not be worth it in and of
itself, however I might want to write another application someday where
knowing this would certainly be useful :)

So IF this seems reasonable, and my controllers are 'FOOcontrol',
'BARcontrol', 'BAZcontrol', and my actions are 'initialize',
'upload_data', 'process', 'generate_invoices'...etc., what is a good way
to stay DRY? In particular I'm having a hard time wrapping my mind
around how the URI's would be handled.

Thanks,
Steve

Search Discussions

  • Ian Docherty at Jul 27, 2011 at 1:46 pm
    Steve
    I'm not sure I have enough information to answer this so my answer may be a bit wide of the mark.

    Would it make more sense, rather than to have different controllers, to abstract the different types of invoice into model objects with common methods, but use inheritance, moose roles, etc. to ring the changes.

    Then in your controllers, perhaps use a query parameter to indicate the type of invoice, create the correct type of object and put it on the stash, using chaining to sort out your other controllers.

    e.g. /invoice creates an invoice object using query argument 'invoice_type' to determine the class to use
    then chain to /invoice/initialize, or invoice/control, or invoice/generate etc.

    Regards
    Ian

    (Sorry for top posting, this email client is rubbish!)

    -----Original Message-----
    From: Steve
    Sent: 27 July 2011 14:30
    To: catalyst@lists.scsys.co.uk
    Subject: [Catalyst] Refactoring Controllers

    Hi all,

    I have a question regarding controller refactoring, and whether
    subclassing (or adding a Moose role) would be a good idea for a
    particular application.

    The application creates 6 different types of invoices, each representing
    a particular type of service. Currently, I have a controller for each
    that handles the various steps that must be taken to produce and
    ultimately send these invoices. ALL OF THESE CONTROLLERS HAVE THE SAME
    ACTIONS, and most of the same logic, which to me says I should refactor
    these controllers...I just don't know how, and also whether the benefit
    is worth the work. Almost certainly it would not be worth it in and of
    itself, however I might want to write another application someday where
    knowing this would certainly be useful :)

    So IF this seems reasonable, and my controllers are 'FOOcontrol',
    'BARcontrol', 'BAZcontrol', and my actions are 'initialize',
    'upload_data', 'process', 'generate_invoices'...etc., what is a good way
    to stay DRY? In particular I'm having a hard time wrapping my mind
    around how the URI's would be handled.

    Thanks,
    Steve



    This e-mail (including any attachments) is confidential, may contain
    proprietary or privileged information and is intended for the named
    recipient(s) only. Unintended recipients are prohibited from taking action
    on the basis of information in this e-mail and must delete all copies.
    Nomura will not accept responsibility or liability for the accuracy or
    completeness of, or the presence of any virus or disabling code in, this
    e-mail. If verification is sought please request a hard copy. Any reference
    to the terms of executed transactions should be treated as preliminary only
    and subject to formal written confirmation by Nomura. Nomura reserves the
    right to monitor e-mail communications through its networks (in accordance
    with applicable laws). No confidentiality or privilege is waived or lost by
    Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is
    a reference to any entity in the Nomura Holdings, Inc. group. Please read
    our Electronic Communications Legal Notice which forms part of this e-mail:
    http://www.Nomura.com/email_disclaimer.htm
  • Steve at Jul 27, 2011 at 2:11 pm
    Ian,

    You may have a point there. The application in question was my first
    *real* Cat app, and as such being explicit was very important. If a
    refactor is to be done, there will be a ton of logic moved to the model,
    as these controllers are pretty big currently.

    I still would like to know how subclassing and/or roles might be applied.

    Thanks!
    On 7/27/2011 9:46 AM, Ian.Docherty@nomura.com wrote:
    Steve
    I'm not sure I have enough information to answer this so my answer may be a bit wide of the mark.

    Would it make more sense, rather than to have different controllers, to abstract the different types of invoice into model objects with common methods, but use inheritance, moose roles, etc. to ring the changes.

    Then in your controllers, perhaps use a query parameter to indicate the type of invoice, create the correct type of object and put it on the stash, using chaining to sort out your other controllers.

    e.g. /invoice creates an invoice object using query argument 'invoice_type' to determine the class to use
    then chain to /invoice/initialize, or invoice/control, or invoice/generate etc.

    Regards
    Ian

    (Sorry for top posting, this email client is rubbish!)

    -----Original Message-----
    From: Steve
    Sent: 27 July 2011 14:30
    To: catalyst@lists.scsys.co.uk
    Subject: [Catalyst] Refactoring Controllers

    Hi all,

    I have a question regarding controller refactoring, and whether
    subclassing (or adding a Moose role) would be a good idea for a
    particular application.

    The application creates 6 different types of invoices, each representing
    a particular type of service. Currently, I have a controller for each
    that handles the various steps that must be taken to produce and
    ultimately send these invoices. ALL OF THESE CONTROLLERS HAVE THE SAME
    ACTIONS, and most of the same logic, which to me says I should refactor
    these controllers...I just don't know how, and also whether the benefit
    is worth the work. Almost certainly it would not be worth it in and of
    itself, however I might want to write another application someday where
    knowing this would certainly be useful :)

    So IF this seems reasonable, and my controllers are 'FOOcontrol',
    'BARcontrol', 'BAZcontrol', and my actions are 'initialize',
    'upload_data', 'process', 'generate_invoices'...etc., what is a good way
    to stay DRY? In particular I'm having a hard time wrapping my mind
    around how the URI's would be handled.

    Thanks,
    Steve



    This e-mail (including any attachments) is confidential, may contain
    proprietary or privileged information and is intended for the named
    recipient(s) only. Unintended recipients are prohibited from taking action
    on the basis of information in this e-mail and must delete all copies.
    Nomura will not accept responsibility or liability for the accuracy or
    completeness of, or the presence of any virus or disabling code in, this
    e-mail. If verification is sought please request a hard copy. Any reference
    to the terms of executed transactions should be treated as preliminary only
    and subject to formal written confirmation by Nomura. Nomura reserves the
    right to monitor e-mail communications through its networks (in accordance
    with applicable laws). No confidentiality or privilege is waived or lost by
    Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is
    a reference to any entity in the Nomura Holdings, Inc. group. Please read
    our Electronic Communications Legal Notice which forms part of this e-mail:
    http://www.Nomura.com/email_disclaimer.htm


    _______________________________________________
    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/
  • Len Jaffe at Jul 27, 2011 at 4:05 pm

    On Wed, Jul 27, 2011 at 10:11 AM, Steve wrote:

    Ian,

    You may have a point there. The application in question was my first
    *real* Cat app, and as such being explicit was very important. If a
    refactor is to be done, there will be a ton of logic moved to the model, as
    these controllers are pretty big currently.

    I still would like to know how subclassing and/or roles might be applied.
    Which are you more comfortable with?

    If you are more comfortable with inheritance, then create the superclass
    first. Afterwards, you can refactor the logic into a role as your comfort
    level dictates.

    Len.
    --
    lenjaffe@jaffesystems.com 614-404-4214
    Proprietor: http://www.theycomewithcheese.com/ - An Homage to Fromage
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110727/e5ef82ac/attachment.htm
  • Alejandro Imass at Jul 29, 2011 at 12:16 am

    On Wed, Jul 27, 2011 at 9:29 AM, Steve wrote:
    Hi all,

    I have a question regarding controller refactoring, and whether subclassing
    (or adding a Moose role) would be a good idea for a particular application.

    The application creates 6 different types of invoices, each representing a
    particular type of service. ?Currently, I have a controller for each that
    handles the various steps that must be taken to produce and ultimately send
    these invoices. ?ALL OF THESE CONTROLLERS HAVE THE SAME ACTIONS, and most of
    the same logic, which to me says I should refactor these controllers...I
    That is what Action Classes are for:


    Look for Action classes in:

    perldoc Catalyst::Manual::ExtendingCatalyst
    just don't know how, and also whether the benefit is worth the work. ?Almost
    certainly it would not be worth it in and of itself, however I might want to
    write another application someday where knowing this would certainly be
    useful :)
    You can also make a base controller type and inherit from that.
    Remember that Catalyst is built over Moose so everytihng Moose you can
    do with Catalyst.
    So IF this seems reasonable, and my controllers are 'FOOcontrol',
    'BARcontrol', 'BAZcontrol', and my actions are 'initialize', 'upload_data',
    'process', 'generate_invoices'...etc., what is a good way to stay DRY? ?In
    particular I'm having a hard time wrapping my mind around how the URI's
    would be handled.
    Action classes and default methods on your root controller.


    --
    Alejandro Imass
    Thanks,
    Steve

    _______________________________________________
    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/
  • Eden Cardim at Jul 29, 2011 at 8:40 pm
    "Steve" == Steve <steve@matsch.com> writes:
    Steve> Hi all,
    Steve> I have a question regarding controller refactoring, and whether subclassing
    Steve> (or adding a Moose role) would be a good idea for a particular application.

    Steve> The application creates 6 different types of invoices, each representing a
    Steve> particular type of service. Currently, I have a controller for each that
    Steve> handles the various steps that must be taken to produce and ultimately send
    Steve> these invoices. ALL OF THESE CONTROLLERS HAVE THE SAME ACTIONS, and most of
    Steve> the same logic, which to me says I should refactor these controllers...I
    Steve> just don't know how, and also whether the benefit is worth the work. Almost
    Steve> certainly it would not be worth it in and of itself, however I might want to
    Steve> write another application someday where knowing this would certainly be
    Steve> useful :)

    Steve> So IF this seems reasonable, and my controllers are 'FOOcontrol',
    Steve> BARcontrol', 'BAZcontrol', and my actions are 'initialize', 'upload_data',
    Steve> process', 'generate_invoices'...etc., what is a good way to stay DRY? In
    Steve> particular I'm having a hard time wrapping my mind around how the URI's
    Steve> would be handled.

    If the actions aren't private, you want to create a base controller to
    preserve the URI paths and keep them consistent across the several
    inheriting controllers. If not, move the methods into a model and use
    delegation.

    --
    Eden Cardim Need help with your Catalyst or DBIx::Class project?
    Code Monkey http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://blog.edencardim.com/ http://www.shadowcat.co.uk/servers/
    http://twitter.com/#!/edenc
  • Steve at Aug 1, 2011 at 6:19 pm
    Thanks to all who responded :)
    On 7/29/2011 4:40 PM, Eden Cardim wrote:
    "Steve" == Steve<steve@matsch.com> writes:
    Steve> Hi all,
    Steve> I have a question regarding controller refactoring, and whether subclassing snip
    If the actions aren't private,...
    They are not, but perhaps they *should* be. Which is *likely* to be
    most maintainable long-term do you think?
    you want to create a base controller to
    preserve the URI paths and keep them consistent across the several
    inheriting controllers. If not, move the methods into a model and use
    delegation.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJul 27, '11 at 1:29p
activeAug 1, '11 at 6:19p
posts7
users5
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase