1 |
package Nos; |
2 |
|
3 |
use 5.008; |
4 |
use strict; |
5 |
use warnings; |
6 |
|
7 |
require Exporter; |
8 |
|
9 |
our @ISA = qw(Exporter); |
10 |
|
11 |
our %EXPORT_TAGS = ( 'all' => [ qw( |
12 |
) ] ); |
13 |
|
14 |
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
15 |
|
16 |
our @EXPORT = qw( |
17 |
); |
18 |
|
19 |
our $VERSION = '0.1'; |
20 |
|
21 |
use Class::DBI::Loader; |
22 |
use Email::Valid; |
23 |
use Email::Send; |
24 |
use Carp; |
25 |
|
26 |
=head1 NAME |
27 |
|
28 |
Nos - Notice Sender core module |
29 |
|
30 |
=head1 SYNOPSIS |
31 |
|
32 |
use Nos; |
33 |
my $nos = new Nos(); |
34 |
|
35 |
=head1 DESCRIPTION |
36 |
|
37 |
Core module for notice sender's functionality. |
38 |
|
39 |
=head1 METHODS |
40 |
|
41 |
=head2 new |
42 |
|
43 |
Create new instance specifing database, user, password and options. |
44 |
|
45 |
my $nos = new Nos( |
46 |
dsn => 'dbi:Pg:dbname=notices', |
47 |
user => 'dpavlin', |
48 |
passwd => '', |
49 |
debug => 1, |
50 |
verbose => 1, |
51 |
); |
52 |
|
53 |
=cut |
54 |
|
55 |
sub new { |
56 |
my $class = shift; |
57 |
my $self = {@_}; |
58 |
bless($self, $class); |
59 |
|
60 |
$self->{'loader'} = Class::DBI::Loader->new( |
61 |
debug => $self->{'debug'}, |
62 |
dsn => $self->{'dsn'}, |
63 |
user => $self->{'user'}, |
64 |
password => $self->{'passwd'}, |
65 |
namespace => "Nos", |
66 |
# additional_classes => qw/Class::DBI::AbstractSearch/, |
67 |
# additional_base_classes => qw/My::Stuff/, |
68 |
relationships => 1, |
69 |
); |
70 |
|
71 |
$self ? return $self : return undef; |
72 |
} |
73 |
|
74 |
=head2 AUTOLOAD |
75 |
|
76 |
Returns class from L<Class::DBI>. |
77 |
|
78 |
my $lists = $nos->lists; |
79 |
|
80 |
is equivalent to: |
81 |
|
82 |
my $lists = $loader->find_class('lists'); |
83 |
|
84 |
=cut |
85 |
|
86 |
#sub AUTOLOAD { |
87 |
# return if $AUTOLOAD =~ m/DESTROY$/; |
88 |
# my ($name) = $AUTOLOAD =~ /([^:]+)$/; |
89 |
# |
90 |
# return $self->{'loader'}->find_class($AUTOLOAD) || |
91 |
# croak "unknown method '$AUTOLOAD' called"; |
92 |
#} |
93 |
|
94 |
=head2 send |
95 |
|
96 |
Send a message using configured mailer. |
97 |
|
98 |
$nos->send("message with headers"); |
99 |
|
100 |
=cut |
101 |
|
102 |
sub send_email { |
103 |
my $self = shift; |
104 |
|
105 |
my $message = shift || return; |
106 |
|
107 |
send IO => $message; |
108 |
} |
109 |
|
110 |
=head2 EXPORT |
111 |
|
112 |
None by default. |
113 |
|
114 |
=head1 SEE ALSO |
115 |
|
116 |
mailman, ezmlm, sympa, L<Mail::Salsa> |
117 |
|
118 |
=head1 AUTHOR |
119 |
|
120 |
Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt> |
121 |
|
122 |
=head1 COPYRIGHT AND LICENSE |
123 |
|
124 |
Copyright (C) 2005 by Dobrica Pavlinusic |
125 |
|
126 |
This library is free software; you can redistribute it and/or modify |
127 |
it under the same terms as Perl itself, either Perl version 5.8.4 or, |
128 |
at your option, any later version of Perl 5 you may have available. |
129 |
|
130 |
|
131 |
=cut |