Re: extending Mail::Box with the manager?
"Anthony D. Urso" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.mail-box |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Jan 07, 2004 at 04:30:34PM +0100, Mark Overmeer wrote:
> > access to mailbox specific methods like loadHead and writeMessages?
>
> The methods you mention are all over the place, so it is a bit
> hard to understand what you would like to do exactly.
>
I'm extending Mail::Box to add some trivial convenience methods, like
one that returns the number of new messages so I don't have to do the
grep { not $_->label('seen') } $folder->messages in other packages.
Also, I setup a companion to the Mail::Message labels() such that it
only returns ones that are set for that message.
The caveat is that I'd rather not know what kind of mailbox is actually
there behind the scenes, so extending Mail::Box::Maildir or whichever would
be counterproductive.
> Nearly all objects which create other objects, like Mail::Box which creates
> Mail::Message's, have instantiation options to configure different classes
> to be produced.
>
> my $f = Mail::Box::Mbox->new(folder => ..., message_type => 'my::own');
>
> package my::own;
> use base 'Mail::Box::Mbox::Message';
>
> This is also possible with the manager (untested code)
>
> $mgr->open(...., message_type => 'my::own');
>
> because all additional options are passed to Mail::Box->new
>
This is exactly what I was looking for, thanks. Is there a corresponding
mailbox_type?
> > sub write { my $self = shift; do stuff...; $self->SUPER::write(@_) }
> >
> > It would seem to me that polymorphism should make this work; however,
> > attempting to call $mbox->write dies stating that MyMail::Box does not
> > implement writeMessages(), which I have no desire to implement.
>
> Yes you do ;-)
> The actual work is done in writeMessages, not in write(). The user
> calls $f->write()... then some general checks are performed, and some
> options parsed. Then the folder type specific writeMessages() is called
> to do "the thing". So don't extend write() itself unless you need
> changes in configuration possibilities for the user.
This was a terrible example, I was just hoping to use a simple one that
was relevent to the writeMessages error, but I don't actually override
$folder->write.
--
Au
PGP Key ID: 0x385B44CB
Fingerprint: 9E9E B116 DB2C D734 C090 E72F 43A0 95C4 385B 44CB
"Maximus vero fugiens a quodam Urso, milite Romano, interemptus est"
- Getica 235