Skip to content

Commit

Permalink
Remove trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
stdweird committed Mar 22, 2015
1 parent 61d57ba commit 481905d
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/main/perl/JSONProfileTyped.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ This module has only C<interpret_node> method for the outside world.
=head2 Type information from JSON::XS
JSON profiles don't contain any explicit type information (as opposed to the
JSON profiles don't contain any explicit type information (as opposed to the
XMLPAN output), e.g. JSON only supports 'number' where XMLPAN has 'long' and 'double'.
It is up to the JSON decoder to provide us with this additional distinction.
The JSON package C<JSON::XS> does not expose the scalar type information.
It is up to the JSON decoder to provide us with this additional distinction.
The JSON package C<JSON::XS> does not expose the scalar type information.
However, we try to come up with correct proper type by relying on the property that
C<JSON::XS> supports C<json_string eq encode(copy(decode(json_string)))>
(implying that the instance returned by C<decode> has the C<XS> types
However, we try to come up with correct proper type by relying on the property that
C<JSON::XS> supports C<json_string eq encode(copy(decode(json_string)))>
(implying that the instance returned by C<decode> has the C<XS> types
(and e.g. no stringification has happened)). However, this is best effort only.
Imperative in the whole typed processing is that values from the decoded JSON
are not assigned to any variable before the type information is extraced via the
are not assigned to any variable before the type information is extraced via the
C<B::svref_2object> method. The scalar types (except for boolean) are then mapped to
the C<B> classes: C<IV> is 'long', C<PV> is 'double' and C<NV> is 'string'.
the C<B> classes: C<IV> is 'long', C<PV> is 'double' and C<NV> is 'string'.
Anything else will be mapped to string (including the combined classes C<PVNV> and C<PVIV>).
TODO: The validity of this assumption is tested in the C<BEGIN{}> (and unittests).
Expand All @@ -58,7 +58,7 @@ use Scalar::Util qw(blessed);

$SIG{__DIE__} = \&confess;

# Turns a JSON Object (an unordered associative array) into a Perl hash
# Turns a JSON Object (an unordered associative array) into a Perl hash
# reference with all the types and metadata from the profile.
sub interpret_nlist
{
Expand Down Expand Up @@ -91,30 +91,30 @@ sub interpret_list
}

# Map the C<B::SV> class from C<B::svref_2object> to a scalar type
# C<IV> is 'long', C<PV> is 'double' and C<NV> is 'string'.
# Anything else will be mapped to string (including the combined
# C<IV> is 'long', C<PV> is 'double' and C<NV> is 'string'.
# Anything else will be mapped to string (including the combined
# classes C<PVNV> and C<PVIV>).
# This only works due to the XS C API used by JSON::XS and if you call
# B::svref_2object directly on the value without assigning it to a
# variable first. This is no magic function that will
# B::svref_2object directly on the value without assigning it to a
# variable first. This is no magic function that will
# "just work" on anything you throw at it.
sub get_scalar_type
{
my $b_obj = shift;

if (! blessed($b_obj)) {
# what was passed?
return 'string';
};

if ($b_obj->isa('B::IV')) {
return 'long';
} elsif ($b_obj->isa('B::NV')) {
return 'double';
} elsif ($b_obj->isa('B::PV')) {
return 'string';
}

# TODO: log all else?
return 'string';

Expand All @@ -124,10 +124,10 @@ sub get_scalar_type
=head2 C<interpret_node>
C<b_obj> is returned by the C<B::svref_2object()> method on the C<doc>
C<b_obj> is returned by the C<B::svref_2object()> method on the C<doc>
(ideally before C<doc> is assigned).
The initial call from C<Fetch> doesn't pass the C<b_obj> value, but that is
The initial call from C<Fetch> doesn't pass the C<b_obj> value, but that is
acceptable since we do not expect the whole JSON profile to be a single scalar value.
=cut
Expand Down

0 comments on commit 481905d

Please sign in to comment.