| 1 | package ZMQ::CZMQ::Zframe; | ||
| 2 | use strict; | ||
| 3 | use ZMQ::CZMQ; | ||
| 4 | use Scalar::Util (); | ||
| 5 | |||
| 6 | sub new { | ||
| 7 | my $class = shift; | ||
| 8 | $class->_wrap(ZMQ::CZMQ::call("zframe_new", @_)); | ||
| 9 | } | ||
| 10 | |||
| 11 | sub _wrap { | ||
| 12 | my ($class, $frame) = @_; | ||
| 13 | bless { _frame => $frame }, $class; | ||
| 14 | } | ||
| 15 | |||
| 16 | sub dup { | ||
| 17 | my $self = shift; | ||
| 18 | my $class = Scalar::Util::blessed($self); | ||
| 19 | $class->_wrap( ZMQ::CZMQ::call("zframe_dup", $self->{_frame}) ); | ||
| 20 | } | ||
| 21 | |||
| 22 | sub send { | ||
| 23 | ZMQ::CZMQ::call("zframe_send", $_[0], $_[1]->{_socket}); | ||
| 24 | } | ||
| 25 | |||
| 26 | # TODO: zframe_new_zero_copy | ||
| 27 | |||
| 28 | BEGIN { | ||
| 29 | # those that construct a new zframe (dup is a special case) | ||
| 30 | foreach my $method (qw(recv recv_nowait)) { | ||
| 31 | eval <<EOM; | ||
| 32 | sub $method { | ||
| 33 | my \$class = shift; | ||
| 34 | my \$raw_frame = ZMQ::CZMQ::call("zframe_$method", \@_); | ||
| 35 | if (! \$raw_frame) { | ||
| 36 | return; | ||
| 37 | } | ||
| 38 | return \$class->_wrap(\$raw_frame); | ||
| 39 | } | ||
| 40 | EOM | ||
| 41 | die if $@; | ||
| 42 | } | ||
| 43 | |||
| 44 | |||
| 45 | foreach my $method (qw(destroy size data strhex strdup streq zero_copy eq more print reset)) { | ||
| 46 | eval <<EOM; | ||
| 47 | sub $method { | ||
| 48 | my \$self = shift; | ||
| 49 | ZMQ::CZMQ::call("zframe_$method", \$self->{_frame}, \@_); | ||
| 50 | } | ||
| 51 | EOM | ||
| 52 | die if $@; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; | ||
| 57 | |||
| 58 | __END__ |