Here's a possible way you might go about this using just two notionally singleton classes.

I haven't addressed data storage and retrieval, although I suspect a DB solution will prove the better choice. (%CFG represents the config data regardless of where and how it was read.)

I've also assumed $WID. This is expected to hold some unique reference to the widget being added.

Consider this as the basis of an approach to a solution rather than the solution itself. I've left it very skeletal as I don't know how this might fit into any existing framework you may have.

package Widget; sub new { my ($class, $rh_def_cfg) = @_; bless { rh_def_cfg => $rh_def_cfg, ro_event => Event->new } => $cl +ass; } sub do_events { my ($self, $WID) = @_; my $rh_event_data = $self->get_event_data($WID); foreach my $event (@{$rh_event_data->{events}}) { $self->{ro_event}->$event($rh_event_data->{params}); } } sub get_event_data { # Use $WID to get type & widget # Use type to get parameters # Use widget to get events (based on type params) # Include other data to be used in Event class # Return hashref with event data } package Event; sub new { my $class = shift; bless {} => $class } sub email { ... } sub log { ... } sub trigger { ... } package main; my %CFG = get_cfg(); # DB or config file my $ro_widget = Widget->new(\%CFG); sub add_widget { # Add here, then: $ro_widget->do_events($WID); }

You might also consider an Aspect-Oriented solution. There's an Aspect module on CPAN which may be useful. (I don't know anything further about this module - others might).

Regards,

PN5


In reply to Re: OT: Design question by Prior Nacre V
in thread OT: Design question by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.