The IDM_State module offers loadable modules a means of keeping state between invocations — this is necessary should Cheesewire be run periodically via cron rather than by its own daemon. State-related data is stored in DBM files via Perl ties.
Creation of an instance of a loadable module calls upon IDM_State:
sub IDM_Template::new_template() { . . my $state = IDM_State->new(STATEMODE => $self->{SIDSCONFIG}->daemon_mode(), DBMFILE => $self->{CLASS}); $self->{STATE} = $state; $self->{STATE}->init_state(FIELD => "LAST_RUN_TIME", DEFLT_FIELD_VAL => $args{LAST_RUN_TIME}); $self->{LOG} = Log->new(PREFIX => $self->{CLASS}, MODULE => $self->{CLASS}, STATE => $self->{STATE}, . . }A reference to the loadable module's state object is passed to the module's instance of the Log class.
Instance of the Log class need to know when to rotate:
sub Log::new() { . . $self->{STATE}->init_state(FIELD => "LOG_LASTTIME", DEFLT_FIELD_VAL => time); . . }and
sub Log::append() { . . if (time > $self->{STATE}->get_state(FIELD => "LOG_LASTTIME") + $self->{MODSCFG}->module_rot_prd($self->{MODULE})) { $self->{STATE}->set_state(FIELD => "LOG_LASTTIME", FIELDVALUE => time); $self->rotate_log(); } . . }
...previous | up (conts) | next... |