# module part sub postSnippets { my ( $self, %options ) = @_; my $headers = { "Content-type" => 'application/json; charset=UTF-8', "Authorization" => 'Basic ' . encode_base64($options{username} . ':' . $options{password}) }; $self->{_client}->POST( $options{url}, encode_json($options{hashRef}), $headers ); return decode_json $self->{_client}->responseContent(); } # script part my $hashRef = { "title" => "Test Title", "code" => "print \"Test POST Request\"", "linenos" => "false", "language" => "perl", "style" => "emacs" }; my %options = ( "url" => $url, "hashRef" => $hashRef, "username" => $username, "password" => $password ); my $post = $object->postSnippets( %options ); print Dumper $post; # output $ perl restClient.pl $VAR1 = { 'linenos' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ), 'id' => 2, 'language' => 'perl', 'code' => 'print "Test POST Request"', 'title' => 'Test Title', 'style' => 'emacs', 'highlight' => 'http://127.0.0.1:8000/snippets/2/highlight/', 'url' => 'http://127.0.0.1:8000/snippets/2/', 'owner' => 'user' };