SMTP.pm

filter: Statementstmt 91.6% 22 / 24 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 91.1% 31 / 34 CC 5 SCAR 12.7
CC
5
Cov
90%
import
5.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.6
« SMTP/Conn.pm ↑ Summary
1 package AnyEvent::SMTP;
2  
3 12 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 m{# trying to cheat with cpants game ;)
7 use strict;
8 use warnings;
9 }x;
10  
11 11 ▶sub import {
Subroutine import: called CC=5 SCAR=16.3
12 11 my $me = shift;
13 11 my $pkg = caller;
14 11 ▶ @_ or return;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return 10 1 11
15 10 for (@_) {
16 20 ▶ if ( $_ eq 'sendmail') {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq 'sendmail') { } 10 10 20
elsif ($_ eq 'smtp_server') { } 10 0 10
17 10 require AnyEvent::SMTP::Client;
18 10 *{$pkg.'::'.$_} = \&AnyEvent::SMTP::Client::sendmail;
19 }
20 elsif ( $_ eq 'smtp_server') {
21 10 require AnyEvent::SMTP::Server;
22 10 *{$pkg.'::'.$_} = \&AnyEvent::SMTP::Server::smtp_server;
23 }
24 else {
25 0 require Carp; Carp::croak "$_ is not exported by $me";
26 }
27 }
28 }
29  
30 =head1 NAME
31  
32 AnyEvent::SMTP - SMTP client and server
33  
34 =cut
35  
36 12 our $VERSION = '0.10';
37  
38  
39 =head1 SYNOPSIS
40  
41 use AnyEvent::SMTP 'sendmail';
42
43 sendmail
44 from => 'mons@cpan.org',
45 to => 'mons@cpan.org', # SMTP host will be detected from addres by MX record
46 data => 'Test message '.time().' '.$$,
47 cb => sub {
48 if (my $ok = shift) {
49 warn "Successfully sent";
50 }
51 if (my $err = shift) {
52 warn "Failed to send: $err";
53 }
54 }
55 ;
56  
57 use AnyEvent::SMTP 'smtp_server';
58  
59 smtp_server undef, 2525, sub {
60 my $mail = shift;
61 warn "Received mail from $mail->{from} to $mail->{to}\n$mail->{data}\n";
62 };
63  
64  
65 =head1 EXPORT
66  
67 By default doesn't export anything. When requested, uses Client or Server exports.
68  
69 =head1 AUTHOR
70  
71 Mons Anderson, C<< <mons at cpan.org> >>
72  
73 =head1 COPYRIGHT & LICENSE
74  
75 Copyright 2009-2011 Mons Anderson, all rights reserved.
76  
77 This program is free software; you can redistribute it and/or modify it
78 under the same terms as Perl itself.
79  
80 =cut
81  
82 12 1; # End of AnyEvent::SMTP
« SMTP/Conn.pm ↑ Summary