File Coverage

blib/lib/Win32/SqlServer/DTS/Credential.pm
Criterion Covered Total %
statement 25 29 86.2
branch 3 6 50.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 2 2 100.0
total 37 46 80.4


line stmt bran cond sub pod time code
1             package Win32::SqlServer::DTS::Credential;
2            
3             =head1 NAME
4            
5             Win32::SqlServer::DTS::Credential - credentials to authenticate against a MS SQL Server 2000
6            
7             =head1 SYNOPSIS
8            
9             use Win32::SqlServer::DTS::Credential;
10            
11             # regular authentication method
12             my $credential = Win32::SqlServer::DTS::Credential->new(
13             {
14             server => 'somedatabase',
15             user => 'user',
16             password => 'password',
17             use_trusted_connection => 0
18             }
19             );
20            
21             #trusted authentication mode
22            
23             my $credential2 =
24             Win32::SqlServer::DTS::Credential->new(
25             { server => 'somedatabase', use_trusted_connection => 1 } );
26            
27             =head1 DESCRIPTION
28            
29             C implements the authentication scheme expected by MS SQL Server connection depending
30             on the mode that will be used (regular authentication or trusted connection).
31            
32             This class was created to be able to invoke the DTS Application C (and others) method in a polymorphic
33             way, since these methods expect a lot of parameters given in the correct order (some parameters are even unused, but
34             one must inform them anyway).
35            
36             One should not need to use this class directly: it is used by the L module and, if
37             you're using this class there is nothing to worry about authentication.
38            
39             =head2 EXPORT
40            
41             Nothing.
42            
43             =cut
44            
45 1     1   13024 use strict;
  1         1  
  1         29  
46 1     1   3 use warnings;
  1         1  
  1         52  
47 1     1   3 use Carp qw(confess);
  1         1  
  1         57  
48 1     1   403 use Hash::Util qw(lock_keys);
  1         1562  
  1         3  
49            
50             =head2 METHODS
51            
52             C does not inherients from any superclass. This means that the methods available in L are
53             not available.
54            
55             =head3 new
56            
57             This method creates a new C object. A hash reference must be passed as a parameter
58             (see L for examples).
59            
60             Depending on the authentication method, C and C are necessary or not. The Trusted Connection does
61             not need such values, but the C method will abort with an error if you pass no keys with the necessary values.
62            
63             A C object will have the following attributes:
64            
65             =over
66            
67             =item *
68             server
69            
70             =item *
71             user
72            
73             =item *
74             password
75            
76             =item *
77             auth_code
78            
79             =back
80            
81             C is defined by the DTS Application object documentation to be defined as explained below:
82            
83             =over
84            
85             =item *
86             Constant DTSSQLStgFlag_Default = 0
87            
88             =item *
89             Constant DTSSQLStgFlag_UseTrustedConnection = 256
90            
91             =back
92            
93             =cut
94            
95             sub new {
96            
97 1     1 1 370 my $class = shift;
98 1         2 my $self = shift;
99            
100 1 50       4 confess 'expects an hash refence as a parameter'
101             unless ( ref($self) eq 'HASH' );
102            
103 1 50       4 unless ( $self->{use_trusted_connection} ) {
104            
105 1 50 33     8 unless (( exists( $self->{user} ) )
106             and ( exists( $self->{password} ) ) )
107             {
108            
109 0         0 confess
110             "Username and password cannot be NULL if trusted connection is not in use\n";
111            
112             }
113 1         2 $self->{auth_code} = 0;
114            
115             #creates the missing keys to avoid issues when invoking to_list method
116             }
117             else {
118            
119 0         0 $self->{user} = '';
120 0         0 $self->{password} = '';
121 0         0 $self->{auth_code} = 256;
122            
123             }
124            
125 1         2 delete $self->{use_trusted_connection};
126            
127 1         3 bless $self, $class;
128 1         1 lock_keys( %{$self} );
  1         7  
129 1         12 return $self;
130            
131             }
132            
133             =head3 to_list
134            
135             Returns all attributes of the object in a ordered list. This will be used during method invoking to authenticate
136             the request against the MS SQL Server. The list is returned in this order:
137            
138             =over
139            
140             =item 1
141             server
142            
143             =item 2
144             user
145            
146             =item 3
147             password
148            
149             =item 4
150             auth_code
151            
152             =back
153            
154             =cut
155            
156             sub to_list {
157            
158 1     1 1 4 my $self = shift;
159 1         4 return $self->{server}, $self->{user}, $self->{password},
160             $self->{auth_code};
161            
162             }
163            
164             1;
165            
166             __END__