Sidef/Types/Glob/SocketHandle.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 91 CC 8 SCAR 16.5
CC
8
Cov
0%
send
12.0
setsockopt
6.0
bind
6.0
CRAP 5.2
1 package Sidef::Types::Glob::SocketHandle;
2  
3 use utf8;
4 use 5.016;
5  
6 use parent qw(
7 Sidef::Types::Glob::FileHandle
8 );
9  
10 sub new {
11 my (undef, $sh, $socket) = @_;
12  
13 bless {
14 fh => $sh,
15 parent => $socket,
16 },
17 __PACKAGE__;
18 }
19  
20 *call = \&new;
21  
22 sub setsockopt {
23 my ($self, $level, $optname, $optval) = @_;
24 (CORE::setsockopt($self->{fh}, $level, "$optname", $optval))
25 ? (Sidef::Types::Bool::Bool::TRUE)
26 : (Sidef::Types::Bool::Bool::FALSE);
27 }
28  
29 sub getsockopt {
30 my ($self, $level, $optname) = @_;
31 Sidef::Types::String::String->new(CORE::getsockopt($self->{fh}, $level, "$optname") // return undef);
32 }
33  
34 sub getpeername {
35 my ($self) = @_;
36 Sidef::Types::String::String->new(CORE::getpeername($self->{fh}) // return undef);
37 }
38  
39 sub getsockname {
40 my ($self) = @_;
41 Sidef::Types::String::String->new(CORE::getsockname($self->{fh}));
42 }
43  
44 sub bind {
45 my ($self, $name) = @_;
46 CORE::bind($self->{fh}, "$name")
47 ? (Sidef::Types::Bool::Bool::TRUE)
48 : (Sidef::Types::Bool::Bool::FALSE);
49 }
50  
51 sub listen {
52 my ($self, $queuesize) = @_;
53  
54 CORE::listen($self->{fh}, $queuesize)
55 ? (Sidef::Types::Bool::Bool::TRUE)
56 : (Sidef::Types::Bool::Bool::FALSE);
57 }
58  
59 sub accept {
60 my ($self) = @_;
61 CORE::accept(my $sh, $self->{fh}) || return undef;
62 Sidef::Types::Glob::SocketHandle->new($sh);
63 }
64  
65 sub connect {
66 my ($self, $name) = @_;
67 CORE::connect($self->{fh}, "$name")
68 ? (Sidef::Types::Bool::Bool::TRUE)
69 : (Sidef::Types::Bool::Bool::FALSE);
70 }
71  
72 sub recv {
73 my ($self, $length, $flags) = @_;
74 my $content = "";
75 CORE::recv($self->{fh}, $content, CORE::int($length), CORE::int($flags)) // return undef;
76 Sidef::Types::String::String->new($content);
77 }
78  
79 sub send {
80 my ($self, $msg, $flags, $to) = @_;
81 CORE::send($self->{fh}, "$msg", CORE::int($flags), defined($to) ? $to->get_value : ())
82 ? (Sidef::Types::Bool::Bool::TRUE)
83 : (Sidef::Types::Bool::Bool::FALSE);
84 }
85  
86 sub shutdown {
87 my ($self, $how) = @_;
88 CORE::shutdown($self->{fh}, $how)
89 ? (Sidef::Types::Bool::Bool::TRUE)
90 : (Sidef::Types::Bool::Bool::FALSE);
91 }
92  
93 1