perl - OOP design suggestion -


i have set of files needs either emailed or ftped(read config). before doing either of these need common operation on files, changing filenames, sanity check, on.

        package class::foo::partners;      use carp;     use data::dumper;     # sanity check , blessing     sub new ($) {         $class = shift;         %attr = @_;         carp::confess('config undefined') unless defined $attr{cfg};         $self = bless({}, $class);         %$self = @_;         return $self;     }      sub process {         $self = shift;          %filestoupload = ();         if ($self->{dbh}->sql($sql, \%filestoupload)) {             $stats;             if (defined $self->{cfg}->{$self->{section}}->{pdf_email_rcpt}) {                 $stats = class::foo::email->new(section => $self->{cfg}->{$self->{section}}, filestoupload => \%filestoupload);                 $stats->sendfiles;             } else {                 $stats = class::foo::ftp->new(section => $self->{cfg}->{$self->{section}}, filestoupload => \%filestoupload);                 $stats->sendfiles;             }         } elsif ($self->{dbh}->{_error}) {             carp::confess($self->{dbh}->{_error});         } else {             print "no files";         }     }       package class::foo::ftp;      use carp;     use data::dumper;     use posix qw( strftime );     use file::temp qw (tempdir) ;     use file::copy;     use net::ftp;      # sanity check , blessing     sub new ($) {         $class = shift;         %attr = @_;         carp::confess('section undefined') unless defined $attr{section};         carp::confess('undefined ftp_host') unless defined $attr{section}->{ftp_host};           $self = bless({}, $class);         %$self = @_;          return $self;     }      sub sendfiles {         $self = shift;         return unless(keys %{$self->{filestoupload}});         #do common task         ..         $self->ftp_connect();         ..         ..     }      package class::foo::email;      use data::dumper;     use mail::sender;     use posix qw( strftime );     use file::temp qw (tempdir) ;     use file::copy;      sub new ($) {         $class = shift;         %attr = @_;         carp::confess('config: undefined pdf_email_subject') unless defined $attr{section}->{pdf_email_subject};         carp::confess('config: undefined pdf_email_from') unless defined $attr{section}->{pdf_email_from};         $self = bless({}, $class);         %$self = @_;          return $self;     }      sub sendfiles {         $self = shift;         return unless(keys %{$self->{filestoupload}});         #do common task         ..         $mailrcpt = $self->{section}->{pdf_email_rcpt};         $sender = new mail::sender {smtp => 'localhost', => $self->{section}->{pdf_email_from}};         $sender->mailfile({ => $mailrcpt,                              subject => $self->{section}->{pdf_email_subject},                              msg => "attached a1 of today's wsje. ",                             ctype => 'application/pdf',                             file => @files } );          $self->{uploaded_count} = @files;     } 

where common operation , when , how call respective child classes?

should use abstraction?

thanks help

check out implementation of mt::filemgr:

https://github.com/openmelody/melody/tree/master/lib/mt

it should give lot of ideas on how perl oop this.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -