Ben,

Thanks for the suggestion. I actually do something very similar to that in 
other situations, but I was hoping for an easier solution here. It is 
basically easier to split up the bigger data files than rewrite a 
significant chunk of my code.

James

On Tuesday, December 31, 2013 2:04:42 PM UTC-6, Ben van Staveren wrote:
>
> [snip] 
>
> You're better off moving all that code into a separate module, something 
> like this: 
>
> package My::Work::Module; 
> use Mojo::Base '-base'; 
>
> has 'app' => undef; 
> has 'log' => sub { 
>    my $self = shift; 
>    return $self->app->log if defined $self->app; 
>    return Mojo::Log->new(\%your_log_options); 
> }; 
> has 'dbh' => undef; 
>
> sub ImportClients { 
> ... 
> } 
>
> 1; 
>
> In your app code you can then use that as such: 
>
> my $work = My::Work::Module->new(app => $self->app, dbh => 
> GetMyDBHandle()); 
>
> And in command line scripts, you'd set up the DBH, and would just do: 
> my $work = My::Work::Module->new(dbh => $my_dbh); 
>
> And it would then not have an app attribute, but i would have a log 
> attribute. You'd just have to make sure that code in the work module 
> calls "$self->log->debug(...)" and not "$self->app->log->debug". 
>
> At least that's how I'd do it.... 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to