@@ -7,111 +7,106 @@ use WebService::Hexonet::Connector::Util;
77use LWP::UserAgent;
88use Data::Dumper;
99
10- our $VERSION = ' 1.12' ;
10+ our $VERSION = ' v1.12.1' ;
11+
1112
1213sub 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 ;
2223}
2324
25+
2426sub enableDebugMode {
25- my $self = shift ;
26- $self -> {" debugMode" } = 1;
27+ my $self = shift ;
28+ $self -> {" debugMode" } = 1;
2729}
2830
31+
2932sub disableDebugMode {
30- my $self = shift ;
31- $self -> {" debugMode" } = 0;
33+ my $self = shift ;
34+ $self -> {" debugMode" } = 0;
3235}
3336
37+
3438sub 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 ) );
4043}
4144
45+
4246sub 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 ;
4650
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 );
4953
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
5256
53- return $self -> call_raw_http( $command , $config );
57+ return $self -> call_raw_http( $command , $config );
5458}
5559
60+
5661sub 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 ;
10498}
10599
100+
106101sub _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 };
115110}
116111
1171121;
0 commit comments