@@ -7,111 +7,106 @@ use WebService::Hexonet::Connector::Util;
7
7
use LWP::UserAgent;
8
8
use Data::Dumper;
9
9
10
- our $VERSION = ' 1.12' ;
10
+ our $VERSION = ' v1.12.1' ;
11
+
11
12
12
13
sub new {
13
- my $class = shift ;
14
- my $self = shift ;
15
- foreach my $key (%$self ) {
16
- my $value = $self -> {$key };
17
- delete $self -> {$key };
18
- $self -> { lc $key } = $value ;
19
- }
20
- $self -> {" debugMode" } = 0;
21
- return bless $self , $class ;
14
+ my $class = shift ;
15
+ my $self = shift ;
16
+ foreach my $key (%$self ) {
17
+ my $value = $self -> {$key };
18
+ delete $self -> {$key };
19
+ $self -> { lc $key } = $value ;
20
+ }
21
+ $self -> {" debugMode" } = 0;
22
+ return bless $self , $class ;
22
23
}
23
24
25
+
24
26
sub enableDebugMode {
25
- my $self = shift ;
26
- $self -> {" debugMode" } = 1;
27
+ my $self = shift ;
28
+ $self -> {" debugMode" } = 1;
27
29
}
28
30
31
+
29
32
sub disableDebugMode {
30
- my $self = shift ;
31
- $self -> {" debugMode" } = 0;
33
+ my $self = shift ;
34
+ $self -> {" debugMode" } = 0;
32
35
}
33
36
37
+
34
38
sub call {
35
- my $self = shift ;
36
- my $command = shift ;
37
- my $config = shift ;
38
- return WebService::Hexonet::Connector::Response-> new(
39
- $self -> call_raw( $command , $config ) );
39
+ my $self = shift ;
40
+ my $command = shift ;
41
+ my $config = shift ;
42
+ return WebService::Hexonet::Connector::Response-> new($self -> call_raw( $command , $config ) );
40
43
}
41
44
45
+
42
46
sub call_raw {
43
- my $self = shift ;
44
- my $command = shift ;
45
- my $config = shift ;
47
+ my $self = shift ;
48
+ my $command = shift ;
49
+ my $config = shift ;
46
50
47
- $config = {} if !defined $config ;
48
- $config = { User => $config } if ( defined $config ) && ( !ref $config );
51
+ $config = {} if !defined $config ;
52
+ $config = { User => $config } if ( defined $config ) && ( !ref $config );
49
53
50
- # TODO check above line if we still need it; $config should always be defined
51
- # because of the line before, so that at least the if branch can be reviewed
54
+ # TODO check above line if we still need it; $config should always be defined
55
+ # because of the line before, so that at least the if branch can be reviewed
52
56
53
- return $self -> call_raw_http( $command , $config );
57
+ return $self -> call_raw_http( $command , $config );
54
58
}
55
59
60
+
56
61
sub call_raw_http {
57
- my $self = shift ;
58
- my $command = shift ;
59
- my $config = shift ;
60
-
61
- my $ua = $self -> _get_useragent();
62
-
63
- my $url = $self -> {url };
64
- my $post = {
65
- s_command => (
66
- scalar WebService::Hexonet::Connector::Util::command_encode(
67
- $command )
68
- )
69
- };
70
- $post -> {s_entity } = $self -> {entity } if exists $self -> {entity };
71
- $post -> {s_login } = $self -> {login } if exists $self -> {login };
72
- $post -> {s_pw } = $self -> {password } if exists $self -> {password };
73
- $post -> {s_user } = $self -> {user } if exists $self -> {user };
74
- $post -> {s_login } = $self -> {login } . " !" . $self -> {role }
75
- if ( exists $self -> {login } ) && ( exists $self -> {role } );
76
-
77
- if ( exists $config -> {user } ) {
78
- if ( exists $post -> {s_user } ) {
79
- $post -> {s_user } .= " " . $config -> {user };
80
- }
81
- else {
82
- $post -> {s_user } = $config -> {user };
83
- }
84
- }
85
- my $r = $self -> {_useragent }-> post( $url , $post );
86
- if ( $r -> is_success ) {
87
- $r = $r -> decoded_content;
88
- }
89
- else {
90
- my $err = $r -> status_line;
91
- $r =
92
- " [RESPONSE]\r\n "
93
- . " CODE=421\r\n "
94
- . " DESCRIPTION=HTTP communication failed;$err \r\n "
95
- . " EOF\r\n " ;
96
-
97
- }
98
- if ( $self -> {" debugMode" } ) {
99
- print STDERR Dumper($command );
100
- print STDERR Dumper($post );
101
- print STDERR Dumper($r );
102
- }
103
- return $r ;
62
+ my $self = shift ;
63
+ my $command = shift ;
64
+ my $config = shift ;
65
+
66
+ my $ua = $self -> _get_useragent();
67
+
68
+ my $url = $self -> {url };
69
+ my $post = {s_command => (scalar WebService::Hexonet::Connector::Util::command_encode($command ))};
70
+ $post -> {s_entity } = $self -> {entity } if exists $self -> {entity };
71
+ $post -> {s_login } = $self -> {login } if exists $self -> {login };
72
+ $post -> {s_pw } = $self -> {password } if exists $self -> {password };
73
+ $post -> {s_user } = $self -> {user } if exists $self -> {user };
74
+ $post -> {s_login } = $self -> {login } . " !" . $self -> {role }
75
+ if ( exists $self -> {login } ) && ( exists $self -> {role } );
76
+
77
+ if ( exists $config -> {user } ) {
78
+ if ( exists $post -> {s_user } ) {
79
+ $post -> {s_user } .= " " . $config -> {user };
80
+ }else {
81
+ $post -> {s_user } = $config -> {user };
82
+ }
83
+ }
84
+ my $r = $self -> {_useragent }-> post( $url , $post );
85
+ if ( $r -> is_success ) {
86
+ $r = $r -> decoded_content;
87
+ }else {
88
+ my $err = $r -> status_line;
89
+ $r =" [RESPONSE]\r\n " . " CODE=421\r\n " . " DESCRIPTION=HTTP communication failed;$err \r\n " . " EOF\r\n " ;
90
+
91
+ }
92
+ if ( $self -> {" debugMode" } ) {
93
+ print STDERR Dumper($command );
94
+ print STDERR Dumper($post );
95
+ print STDERR Dumper($r );
96
+ }
97
+ return $r ;
104
98
}
105
99
100
+
106
101
sub _get_useragent {
107
- my $self = shift ;
108
- return $self -> {_useragent } if exists $self -> {_useragent };
109
- $self -> {_useragent } = LWP::UserAgent-> new(
110
- agent => " Hexonet-perl/$WebService::Hexonet::Connector::VERSION " ,
111
- keep_alive => 4,
112
- );
113
- $self -> {_useragent }-> default_header( ' Expect' , ' ' );
114
- return $self -> {_useragent };
102
+ my $self = shift ;
103
+ return $self -> {_useragent } if exists $self -> {_useragent };
104
+ $self -> {_useragent } = LWP::UserAgent-> new(
105
+ agent => " Hexonet-perl/$WebService::Hexonet::Connector::VERSION " ,
106
+ keep_alive => 4,
107
+ );
108
+ $self -> {_useragent }-> default_header( ' Expect' , ' ' );
109
+ return $self -> {_useragent };
115
110
}
116
111
117
112
1;
0 commit comments