Skip Menu |

This queue is for tickets about the XML-Compile CPAN distribution.

Report information
The Basics
Id: 69524
Status: resolved
Priority: 0/
Queue: XML-Compile

People
Owner: Nobody in particular
Requestors: BitCard [...] ResonatorSoft.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in:
  • 0.01
  • 0.02
  • 0.04
  • 0.05
  • 0.07
  • 0.08
  • 0.11
  • 0.12
  • 0.15
  • 0.16
  • 0.17
  • 0.18
  • 0.5
  • 0.51
  • 0.52
  • 0.53
  • 0.54
  • 0.55
  • 0.56
  • 0.57
  • 0.58
  • 0.59
  • 0.60
  • 0.63
  • 0.64
  • 0.65
  • 0.66
  • 0.67
  • 0.68
  • 0.69
  • 0.70
  • 0.71
  • 0.72
  • 0.73
  • 0.74
  • 0.75
  • 0.76
  • 0.77
  • 0.78
  • 0.79
  • 0.80
  • 0.81
  • 0.82
  • 0.83
  • 0.84
  • 0.85
  • 0.86
  • 0.87
  • 0.88
  • 0.89
  • 0.90
  • 0.91
  • 0.92
  • 0.93
  • 0.93-raw
  • 0.94
  • 0.95
  • 0.96
  • 0.97
  • 0.98
  • 0.99
  • 1.00
  • 1.01
  • 1.02
  • 1.03
  • 1.04
  • 1.05
  • 1.06
  • 1.07
  • 1.08
  • 1.09
  • 1.10
  • 1.11
  • 1.12
  • 1.13
  • 1.14
  • 1.15
  • 1.16
  • 1.17
  • 1.18
  • 1.19
  • 1.20
  • 1.21
  • 1.22
Fixed in: (no value)



Subject: NIL constant needs option of using undef
Using the constant string of 'NIL' doesn't seem to be the best translation into a Perl hash tree. It means that programmers have to detect both zero-based checks (!$a) and the string 'NIL' for any checks. Code like this would not work: $XML->{a} ||= "test"; # still keeps a NIL field as NIL However, other options may be inappropriate. Using 0 or '' is not the same as a NULL value. But, undef works. It's more or less the NULL field for Perl. However, there is still a difference between a non-existent tag and nillable data. So, using the interpret_nillable_as_optional option is NOT the same as defining NIL as undef. If the NIL constant was set to undef, you can still tell the difference in Perl: <root><a>test</a><b></b><c xsi:nil="true" /></root> say 'A = True' if ($XML->{a}); # True say 'B = True' if ($XML->{b}); # False say 'B = Defined' if (defined $XML->{b}); # True say 'C = True' if ($XML->{c}); # False say 'C = Defined' if (defined $XML->{c}); # False say 'C = Exists' if (exists $XML->{c}); # True say 'D = True' if ($XML->{d}); # False say 'D = Defined' if (defined $XML->{d}); # False say 'D = Exists' if (exists $XML->{d}); # False Therefore, there should be a nil_value option for the reader/writer. It would default to 'NIL' (for compatibility), but you can set it to whatever value you want, including undef. Say somebody is used to NULL in databases, or need to feed the reader to some sort of DB writer that uses that string. They could set it to 'NULL', instead. Or fix Perl matching problem by setting it to undef. I can write a patch, but I'll need a hour to digest the code. Also wanted your option on the manner.
Subject: Re: [rt.cpan.org #69524] NIL constant needs option of using undef
Date: Sun, 17 Jul 2011 13:47:28 +0200
To: Brendan Byrd via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Brendan Byrd via RT (bug-XML-Compile@rt.cpan.org) [110716 18:05]: Show quoted text
> Sat Jul 16 14:05:05 2011: Request 69524 was acted upon. > Transaction: Ticket created by SineSwiper > Queue: XML-Compile > Subject: NIL constant needs option of using undef > Using the constant string of 'NIL' doesn't seem to be the best > translation into a Perl hash tree. It means that programmers have to > detect both zero-based checks (!$a) and the string 'NIL' for any checks.
Longer answer after my holidays. There is a big difference between NIL and undef. Nillable means explicitly missing, undef is implicitly missing. <element name="t" minOccurs="0" nillable="true"/> t => undef # or missing -> no element t => 'NIL' -> <t nil="true"/> As some schemas confuse users by offering both optional als nillable for elements I have to distiguish between them. Besides, having an explict NIL in the perl hash where the schema requires an explicit NIL in the message seems justified. The 'interpret_nillable_as_optional" is used for some schema's where the designed did not understand the difference between both. So, where messages are sent without elements which are not optional but only nillable. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions drs Mark A.C.J. Overmeer MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
From: BitCard [...] ResonatorSoft.org
On Sun Jul 17 07:47:48 2011, Mark@Overmeer.net wrote: Show quoted text
> There is a big difference between NIL and undef. Nillable means > explicitly missing, undef is implicitly missing. > > <element name="t" minOccurs="0" nillable="true"/> > > t => undef # or missing -> no element > t => 'NIL' -> <t nil="true"/>
You might be misunderstanding what I'm asking for. I'm not asking for an undef as an implicitly missing value. I'm asking for it as an -explicitly- missing value. From your example above, it transforms into: !exists t -> no element t => undef -> <t nil="true"/> The element 't' as a hash, array, or a LibXML node can still exist, even if the value inside of it is 'undef'. Perl's undef is the NULL value for the language, so it should be used as such, so that the underlying code that accesses the hashes "just works". It's unnecessary busy work to write 'NIL' exceptions to everything or a walk_hash_tree sub just to remove (and then readd) all of the NILs from the tree. Show quoted text
> The 'interpret_nillable_as_optional" is used for some schema's where > the designed did not understand the difference between both. So, > where messages are sent without elements which are not optional but > only nillable.
Yep, but that's different than assigning undef/NIL to an element. I don't want to remove the element; I want the hash to translate NIL to undef and back, so that the Perl code works better.
Subject: Re: [rt.cpan.org #69524] NIL constant needs option of using undef
Date: Fri, 22 Jul 2011 16:03:59 +0200
To: Brendan Byrd via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Brendan Byrd via RT (bug-XML-Compile@rt.cpan.org) [110717 17:33]: Show quoted text
> !exists t -> no element > t => undef -> <t nil="true"/>
Where you win in the case of schema's using NIL (quite rare), you loose for everyone who wants to write { s => take_values() , t => collect_data() } where that function may return undef. If I have a look at my own code (many modules), that approach would seriously lengten my implementations. But there are many other places, with complex structures which will break. For instance, "undef" is also false for booleans. Show quoted text
> Perl's undef is the NULL value for the language, so it should be used > as such, so that the underlying code that accesses the hashes "just works".
Perl's undef is an implicit NULL (missing value), not an explicit NULL (NIL). See: my $x; # value now is undef Show quoted text
> It's unnecessary busy work > to write 'NIL' exceptions to everything or a walk_hash_tree sub just to > remove (and then readd) all of the NILs from the tree.
That's the weird thing of writing explicit NILs: they give you extra work but have no clear benefit. You can use them on things like this: name => 'filled in' address => undef # unknown whether there is one phone => NIL # explicitly state we do not have one But that's their only correct purpose. Show quoted text
> Yep, but that's different than assigning undef/NIL to an element. I > don't want to remove the element; I want the hash to translate NIL to > undef and back, so that the Perl code works better.
I do understand what you want, but it will complicate the code for everyone including you! -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions drs Mark A.C.J. Overmeer MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Unless there are new arguments in favor, this idea will not get implemented.