Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 8085acf

Browse files
perltidy'fied source code
1 parent 2de3f42 commit 8085acf

File tree

7 files changed

+365
-355
lines changed

7 files changed

+365
-355
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.vstags
1+
.vstags
2+
**/*.bak
3+
**/*.tdy

lib/HEXONET/apiconnector.pm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use HEXONET::apiconnector::Connection;
77

88
our $VERSION = '1.10';
99

10-
1110
sub connect {
12-
return new HEXONET::apiconnector::Connection(@_);
11+
return new HEXONET::apiconnector::Connection(@_);
1312
}
1413

1514
1;
@@ -251,4 +250,4 @@ L<https://www.hexonet.net>
251250
252251
MIT
253252
254-
=cut
253+
=cut

lib/HEXONET/apiconnector/connection.pm

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,75 @@ use LWP::UserAgent;
1010
our $VERSION = '1.10';
1111

1212
sub new {
13-
my $class = shift;
14-
my $self = {@_};
15-
foreach my $key (%$self) {
16-
my $value = $self->{$key};
17-
delete $self->{$key};
18-
$self->{lc $key} = $value;
19-
}
20-
return bless $self, $class;
13+
my $class = shift;
14+
my $self = {@_};
15+
foreach my $key (%$self) {
16+
my $value = $self->{$key};
17+
delete $self->{$key};
18+
$self->{ lc $key } = $value;
19+
}
20+
return bless $self, $class;
2121
}
2222

23-
2423
sub call {
25-
my $self = shift;
26-
my $command = shift;
27-
my $config = shift;
28-
return HEXONET::apiconnector::Response->new($self->call_raw($command, $config));
24+
my $self = shift;
25+
my $command = shift;
26+
my $config = shift;
27+
return HEXONET::apiconnector::Response->new(
28+
$self->call_raw( $command, $config ) );
2929
}
3030

31-
3231
sub call_raw {
33-
my $self = shift;
34-
my $command = shift;
35-
my $config = shift;
32+
my $self = shift;
33+
my $command = shift;
34+
my $config = shift;
3635

37-
$config = {} if !defined $config;
38-
$config = { User => $config } if (defined $config) && (!ref $config);
36+
$config = {} if !defined $config;
37+
$config = { User => $config } if ( defined $config ) && ( !ref $config );
3938

40-
return $self->call_raw_http($command, $config);
39+
return $self->call_raw_http( $command, $config );
4140
}
4241

43-
4442
sub call_raw_http {
45-
my $self = shift;
46-
my $command = shift;
47-
my $config = shift;
48-
49-
my $ua = $self->_get_useragent();
50-
51-
my $url = $self->{url};
52-
my $post = {s_command => (scalar HEXONET::apiconnector::Util::command_encode($command))};
53-
$post->{s_entity} = $self->{entity} if exists $self->{entity};
54-
$post->{s_login} = $self->{login} if exists $self->{login};
55-
$post->{s_pw} = $self->{password} if exists $self->{password};
56-
$post->{s_user} = $self->{user} if exists $self->{user};
57-
$post->{s_login} = $self->{login} . "!" . $self->{role} if exists $self->{role};
58-
59-
if ( exists $config->{user} ) {
60-
if ( exists $post->{s_user} ) {
61-
$post->{s_user} .= " ".$config->{user};
62-
}else {
63-
$post->{s_user} = $config->{user};
64-
}
65-
}
66-
67-
my $response = $self->{_useragent}->post($url, $post );
68-
return $response->content();
43+
my $self = shift;
44+
my $command = shift;
45+
my $config = shift;
46+
47+
my $ua = $self->_get_useragent();
48+
49+
my $url = $self->{url};
50+
my $post =
51+
{ s_command =>
52+
( scalar HEXONET::apiconnector::Util::command_encode($command) ) };
53+
$post->{s_entity} = $self->{entity} if exists $self->{entity};
54+
$post->{s_login} = $self->{login} if exists $self->{login};
55+
$post->{s_pw} = $self->{password} if exists $self->{password};
56+
$post->{s_user} = $self->{user} if exists $self->{user};
57+
$post->{s_login} = $self->{login} . "!" . $self->{role}
58+
if exists $self->{role};
59+
60+
if ( exists $config->{user} ) {
61+
if ( exists $post->{s_user} ) {
62+
$post->{s_user} .= " " . $config->{user};
63+
}
64+
else {
65+
$post->{s_user} = $config->{user};
66+
}
67+
}
68+
69+
my $response = $self->{_useragent}->post( $url, $post );
70+
return $response->content();
6971

7072
}
7173

72-
7374
sub _get_useragent {
74-
my $self = shift;
75-
return $self->{_useragent} if exists $self->{_useragent};
76-
$self->{_useragent} = new LWP::UserAgent(
77-
agent => "HEXONET-perl/$HEXONET::apiconnector::VERSION",
78-
keep_alive => 4
79-
);
80-
return $self->{_useragent};
75+
my $self = shift;
76+
return $self->{_useragent} if exists $self->{_useragent};
77+
$self->{_useragent} = new LWP::UserAgent(
78+
agent => "HEXONET-perl/$HEXONET::apiconnector::VERSION",
79+
keep_alive => 4
80+
);
81+
return $self->{_useragent};
8182
}
8283

83-
1;
84+
1;

lib/HEXONET/apiconnector/response.pm

Lines changed: 96 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -11,141 +11,145 @@ use overload
1111
our $VERSION = '1.10';
1212

1313
sub new {
14-
my $class = shift;
15-
my $response = shift;
16-
my $self = {};
17-
18-
if ( (ref $response) eq "HASH" ) {
19-
$self->{_response_hash} = $response;
20-
}elsif ( !ref $response ) {
21-
$self->{_response_string} = $response;
22-
}else {
23-
die "Unsupported Class: ".(ref $response);
24-
}
25-
26-
bless $self, $class;
27-
$self->{test} = 1;
28-
29-
return bless $self, $class;
14+
my $class = shift;
15+
my $response = shift;
16+
my $self = {};
17+
18+
if ( ( ref $response ) eq "HASH" ) {
19+
$self->{_response_hash} = $response;
20+
}
21+
elsif ( !ref $response ) {
22+
$self->{_response_string} = $response;
23+
}
24+
else {
25+
die "Unsupported Class: " . ( ref $response );
26+
}
27+
28+
bless $self, $class;
29+
$self->{test} = 1;
30+
31+
return bless $self, $class;
3032
}
3133

32-
3334
sub as_string {
34-
my $self = shift;
35+
my $self = shift;
3536

36-
return $self->{_response_string};
37+
return $self->{_response_string};
3738
}
3839

39-
4040
sub _as_hash_op {
41-
my $self = shift;
41+
my $self = shift;
4242

43-
# Don't hide the $self hash if called from within class
44-
my ($pkg) = caller 0;
45-
return $self if $pkg->isa('HEXONET::apiconnector::Response');
46-
return $self->as_hash();
43+
# Don't hide the $self hash if called from within class
44+
my ($pkg) = caller 0;
45+
return $self if $pkg->isa('HEXONET::apiconnector::Response');
46+
return $self->as_hash();
4747
}
4848

49-
5049
sub as_hash {
51-
my $self = shift;
50+
my $self = shift;
5251

53-
return $self->{_response_hash} if defined $self->{_response_hash};
54-
$self->{_response_hash} = HEXONET::apiconnector::Util::response_to_hash($self->{_response_string});
55-
return $self->{_response_hash};
52+
return $self->{_response_hash} if defined $self->{_response_hash};
53+
$self->{_response_hash} = HEXONET::apiconnector::Util::response_to_hash(
54+
$self->{_response_string} );
55+
return $self->{_response_hash};
5656
}
5757

58-
5958
sub as_list_hash {
60-
my $self = shift;
59+
my $self = shift;
6160

62-
return $self->{_response_list_hash} if defined $self->{_response_list_hash};
63-
$self->{_response_list_hash} = HEXONET::apiconnector::Util::response_to_list_hash($self->as_hash());
64-
return $self->{_response_list_hash};
61+
return $self->{_response_list_hash} if defined $self->{_response_list_hash};
62+
$self->{_response_list_hash} =
63+
HEXONET::apiconnector::Util::response_to_list_hash( $self->as_hash() );
64+
return $self->{_response_list_hash};
6565
}
6666

67-
6867
sub as_list {
69-
my $self = shift;
70-
my $list_hash = $self->as_list_hash();
71-
if (wantarray) {
72-
return @{$list_hash->{ITEMS}};
73-
}
74-
return $list_hash->{ITEMS};
68+
my $self = shift;
69+
my $list_hash = $self->as_list_hash();
70+
if (wantarray) {
71+
return @{ $list_hash->{ITEMS} };
72+
}
73+
return $list_hash->{ITEMS};
7574
}
7675

77-
7876
sub code {
79-
my $self = shift;
80-
return $self->as_hash()->{CODE};
77+
my $self = shift;
78+
return $self->as_hash()->{CODE};
8179
}
8280

83-
8481
sub description {
85-
my $self = shift;
86-
return $self->as_hash()->{DESCRIPTION};
82+
my $self = shift;
83+
return $self->as_hash()->{DESCRIPTION};
8784
}
8885

89-
9086
sub properties {
91-
my $self = shift;
92-
return $self->as_hash()->{PROPERTY};
87+
my $self = shift;
88+
return $self->as_hash()->{PROPERTY};
9389
}
9490

95-
9691
sub runtime {
97-
my $self = shift;
98-
return $self->as_hash()->{RUNTIME};
92+
my $self = shift;
93+
return $self->as_hash()->{RUNTIME};
9994
}
10095

101-
10296
sub queuetime {
103-
my $self = shift;
104-
return $self->as_hash()->{QUEUETIME};
97+
my $self = shift;
98+
return $self->as_hash()->{QUEUETIME};
10599
}
106100

107-
108101
sub property {
109-
my $self = shift;
110-
my $property = shift;
111-
my $index = shift;
112-
my $p = $self->as_hash()->{PROPERTY};
113-
if ( defined $index ) {
114-
return (LIST { undef }SCALAR { undef }) unless exists $p->{$property};
115-
return $p->{$property}[$index];
116-
}
117-
if (wantarray) {
118-
return () unless exists $p->{$property};
119-
return @{$p->{$property}};
120-
}
121-
return (LIST { undef }SCALAR { undef }) unless exists $p->{$property};
122-
return $p->{$property};
102+
my $self = shift;
103+
my $property = shift;
104+
my $index = shift;
105+
my $p = $self->as_hash()->{PROPERTY};
106+
if ( defined $index ) {
107+
return ( LIST { undef } SCALAR { undef } )
108+
unless exists $p->{$property};
109+
return $p->{$property}[$index];
110+
}
111+
if (wantarray) {
112+
return () unless exists $p->{$property};
113+
return @{ $p->{$property} };
114+
}
115+
return ( LIST { undef } SCALAR { undef } ) unless exists $p->{$property};
116+
return $p->{$property};
123117
}
124118

125-
126119
sub is_success {
127-
my $self = shift;
128-
return $self->as_hash()->{CODE} =~ /^2/;
120+
my $self = shift;
121+
return $self->as_hash()->{CODE} =~ /^2/;
129122
}
130123

131-
132124
sub is_tmp_error {
133-
my $self = shift;
134-
return $self->as_hash()->{CODE} =~ /^4/;
135-
}
136-
137-
sub columns { my $self = shift; return $self->as_list_hash()->{COLUMNS}; }
138-
sub first { my $self = shift; return $self->as_list_hash()->{FIRST}; }
139-
sub last { my $self = shift; return $self->as_list_hash()->{LAST}; }
140-
sub count { my $self = shift; return $self->as_list_hash()->{COUNT}; }
141-
sub limit { my $self = shift; return $self->as_list_hash()->{LIMIT}; }
142-
sub total { my $self = shift; return $self->as_list_hash()->{TOTAL}; }
143-
sub pages { my $self = shift; return $self->as_list_hash()->{PAGES}; }
144-
sub page { my $self = shift; return $self->as_list_hash()->{PAGE}; }
125+
my $self = shift;
126+
return $self->as_hash()->{CODE} =~ /^4/;
127+
}
128+
129+
sub columns { my $self = shift; return $self->as_list_hash()->{COLUMNS}; }
130+
sub first { my $self = shift; return $self->as_list_hash()->{FIRST}; }
131+
sub last { my $self = shift; return $self->as_list_hash()->{LAST}; }
132+
sub count { my $self = shift; return $self->as_list_hash()->{COUNT}; }
133+
sub limit { my $self = shift; return $self->as_list_hash()->{LIMIT}; }
134+
sub total { my $self = shift; return $self->as_list_hash()->{TOTAL}; }
135+
sub pages { my $self = shift; return $self->as_list_hash()->{PAGES}; }
136+
sub page { my $self = shift; return $self->as_list_hash()->{PAGE}; }
145137
sub prevpage { my $self = shift; return $self->as_list_hash()->{PREVPAGE}; }
146-
sub prevpagefirst { my $self = shift; return $self->as_list_hash()->{PREVPAGEFIRST}; }
138+
139+
sub prevpagefirst {
140+
my $self = shift;
141+
return $self->as_list_hash()->{PREVPAGEFIRST};
142+
}
147143
sub nextpage { my $self = shift; return $self->as_list_hash()->{NEXTPAGE}; }
148-
sub nextpagefirst { my $self = shift; return $self->as_list_hash()->{NEXTPAGEFIRST}; }
149-
sub lastpagefirst { my $self = shift; return $self->as_list_hash()->{LASTPAGEFIRST}; }
150144

151-
1;
145+
sub nextpagefirst {
146+
my $self = shift;
147+
return $self->as_list_hash()->{NEXTPAGEFIRST};
148+
}
149+
150+
sub lastpagefirst {
151+
my $self = shift;
152+
return $self->as_list_hash()->{LASTPAGEFIRST};
153+
}
154+
155+
1;

0 commit comments

Comments
 (0)