File Coverage

blib/lib/Test/Reporter/Transport/Outlook.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Test::Reporter::Transport::Outlook;
2              
3             =head1 NAME
4              
5             Test::Reporter::Transport::Outlook - MS Outlook as transport for Test::Reporter
6              
7             =cut
8              
9 3     3   119751 use strict;
  3         9  
  3         142  
10 3     3   19 use warnings;
  3         6  
  3         131  
11              
12             require 5.008_008;
13              
14 3     3   18 use base 'Test::Reporter::Transport';
  3         17  
  3         2632  
15 3     3   4195 use Mail::Outlook;
  0            
  0            
16             use Params::Validate qw(:types validate_pos);
17             use Devel::AssertOS qw(MSWin32);
18              
19             =head1 SYNOPSIS
20              
21             use warnings;
22             use strict;
23             use Test::Reporter;
24             use Test::Reporter::Transport::Outlook;
25              
26             my $reporter = Test::Reporter->new(
27             grade => 'fail',
28             distribution => 'Mail-Freshmeat-1.20',
29             from => 'whoever@wherever.net (Whoever Wherever)',
30             comments => 'output of a failed make test goes here...',
31             via => 'CPANPLUS X.Y.Z',
32             );
33              
34             my $sender = Test::Reporter::Transport::Outlook->new(0);
35              
36             $sender->send($reporter);
37              
38             =head1 DESCRIPTION
39              
40             If you want to test Perl modules for CPAN but is located in a very restricted environment, without HTTP or SMTP access
41             outside the network and can count only with an Outlook and Exchange server to send emails, this module is for you.
42              
43             This module will use C module with MS Outlook to create a new email message. This message will contain
44             all information regarding the test report and I be ready to be sent I new security patches of Outlook
45             didn't forbid that.
46              
47             As an alternative, the message can be saved on the "Drafts" (or whatever is called in your computer) or can be displayed
48             so you will only need to click (or review before clicking) the report. Default behavior is to save the email so you can
49             avoid having lot's of new email messages being opened if you're testing real hard new distributions.
50              
51             Of course, this module expects that you're in a MS Windows machine with MS Outlook installed. This module will not work
52             in other operational systems.
53              
54             =head1 USAGE
55              
56             See L and L for general usage information.
57              
58             =cut
59              
60             our $VERSION = '0.01';
61              
62             =head2 Transport Arguments
63              
64             $report->transport_args( 1 );
65              
66             See C method to understand this parameter.
67              
68             =head1 METHODS
69              
70             These methods are only for internal use by Test::Reporter.
71              
72             =head2 new
73              
74             my $sender = Test::Reporter::Transport::Outlook->new( 0 );
75              
76             The C method is the object constructor.
77              
78             There is an optional parameter that is related if the email will be saved in the Drafts folder (the default behavior)
79             or displayed to the user executing this module. The valid values are true (1) or false (0) respectivally. Anything
80             else will generate an exception.
81              
82             To save the message, nothing needs to be passed. To display the message, pass 0 as an argument.
83              
84             The message will be saved or displayed upon invocation of the method C.
85              
86             =cut
87              
88             sub new {
89              
90             my $class = shift;
91              
92             my @params =
93             validate_pos( @_, { type => SCALAR, regex => qr/^1|0$/, default => 1 } );
94              
95             my $self =
96             { _outlook => Mail::Outlook->new(), _is_draft => shift(@params) };
97              
98             return bless $self, $class;
99             }
100              
101             =head2 get_outlook
102              
103             Returns the C object that represents the MS Outlook application.
104              
105             =cut
106              
107             sub get_outlook {
108              
109             my $self = shift;
110              
111             return $self->{_outlook};
112              
113             }
114              
115             =head2 send
116              
117             Display or save the message in the Outlook, depends on the values defined during object creation. See the method
118             C for more details.
119              
120             Expects as a parameter a C object. Returns true in case of success or false in failure (1 or 0);
121              
122             =cut
123              
124             sub send {
125              
126             validate_pos(
127             @_,
128             { type => OBJECT, isa => 'Test::Reporter::Transport::Outlook' },
129             { type => OBJECT, isa => 'Test::Reporter' }
130             );
131              
132             my ( $self, $report ) = @_;
133              
134             my $message = $self->get_outlook()->create();
135              
136             $message->To( $report->address() );
137             $message->Subject( $report->subject() );
138             $message->Body( $report->report() );
139              
140             if ( $self->{_is_draft} ) {
141              
142             return $message->save();
143              
144             }
145             else {
146              
147             return $message->display();
148              
149             }
150              
151             }
152              
153             1;
154              
155             __END__