Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
incorrect methods yield success

Sorry, that's not really much to go on, the behavior looks correct to me. $jsonpackage->new creates a new object (in this case of type Cpanel::JSON::XS). encode is a method, but encode_json is not, but in the second call of jsonsolute, $json->$jsonefunction calls encode_json as a method, meaning that the parameters that the function encode_json sees are actually ($json, {key => 'value'}), and it doesn't know how to handle the object $json, which is of type Cpanel::JSON::XS, so it dies.

use warnings; use strict; use Data::Dump; dd jsonsolute('JSON::MaybeXS', 'encode', 'decode'); dd jsonsolute(); print "Done\n"; sub jsonsolute { my ($jsonpackage, $jsonefunction, $jsondfunction) = @_; $jsonpackage ||= 'JSON::MaybeXS'; $jsonefunction ||= 'encode_json'; $jsondfunction ||= 'decode_json'; dd $jsonpackage, $jsonefunction, $jsondfunction; if ( !defined eval "require $jsonpackage; 1" ) { die "package $jsonpackage missing\n"; } else { my $json = $jsonpackage->new(pretty => 1, canonical => 1); dd $json; my $encoded = $json->$jsonefunction({key => 'value'}); my $decoded = $json->$jsondfunction('{"key":"value"}'); dd $encoded, $decoded; return $encoded, $decoded; } } __END__ ("JSON::MaybeXS", "encode", "decode") bless(do{\(my $o = "")}, "Cpanel::JSON::XS") ("{\n \"key\" : \"value\"\n}\n", { key => "value" }) ("{\n \"key\" : \"value\"\n}\n", { key => "value" }) ("JSON::MaybeXS", "encode_json", "decode_json") bless(do{\(my $o = "")}, "Cpanel::JSON::XS") encountered type (HASH(0x52aeb6d595a8), 0x80801) was specified for 'Cp +anel::JSON::XS=SCALAR(0x52aeb6e99850)' at line 20.

In reply to Re: incorrect methods yield success by haukex
in thread incorrect methods yield success by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2020-09-29 08:55 GMT
    Find Nodes?
      Voting Booth?
      If at first I donít succeed, I Ö

      Results (146 votes). Check out past polls.