in reply to Re: Best practices passing database handles, cgi objects, etc.
in thread Best practices passing database handles, cgi objects, etc.

If I understand the example correctly, then the main program (the one calling MyApp) will look something like this?

use MyApp; my $myapp->new( cgi => CGI->new(), session => CGI::Session->new(), database => DBI->connect() ); print CGI->header().$myapp->do_something();

Replies are listed 'Best First'.
Re^3: Best practices passing database handles, cgi objects, etc.
by tobyink (Canon) on Feb 19, 2014 at 07:37 UTC

    Yes, or better:

    use MyApp; my $myapp->new( cgi => CGI->new(), session => CGI::Session->new(), database => DBI->connect() ); print $myapp->process_request();

    Where the process_request method is something like:

    sub process_request { my $self = shift; $self->cgi->header . $self->do_something; }
    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re^3: Best practices passing database handles, cgi objects, etc.
by choroba (Cardinal) on Feb 19, 2014 at 07:40 UTC
    I usually include all the functionality into the class so I do not have to care about its implementation in the main application. Therefore, I would use
    $myapp->header

    instead of

    CGI->header

    If you later decide you need to change something in the header (e.g. the encoding/charset), you just edit the header method of the class.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ