[Xml-compile] Re: Xml-compile Digest, Vol 25, Issue 10

Mark Overmeer mark at overmeer.net
Tue Apr 27 07:53:38 GMT 2010


* Titi Ala'ilima (titi at leadkarma.com) [100426 13:23]:
> On Mon, Apr 26, 2010 at 8:00 AM, <xml-compile-request at lists.scsys.co.uk>
> Just a suggestion, since this problem requires correction on two separate
> lines, it's a sign that there is some unhelpful repetition.  Probably worth
> putting the redundant parts of these patterns into shared variables to make
> maintenance easier in the long run, e.g.:

>     my $yearmonth_re = '(?:\d+Y)?(?:\d+M)?';
>     my $daytime_re = '(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?'; 
> 
>     $builtin_types{duration} =
>      { parse   => \&_collapse
>      , check   => sub { my $val = $_[0]; $val =~ s/\s+//g; $val =~
>          m/^\-?P${yearmonth_re}${daytime_re}$/ }
>      , example => 'P9M2DT3H5M'
>      };
> 
> It has the additional benefit of making it clearer what the patterns 
> are trying to accomplish.

I have implemented that for the date/time types.  However, in this case,
this seems not to help abstraction. Avoiding replication is one thing,
but when it needs helpers which are feeling uncomforatable, then it
probably does not help the maintenance of the code.

In this case, it is weird that the "day" is in the second. The usual
construct would be YMD and HMS. However, the schema designers split the
"duration" on a different spot. Probably with a certain convenience in
mind, but quite distinct from other applications. So, the abstractions
of the two components you suggest do not come easy enough.

Avoiding repetition here gives +1 for your solution. The unusual split
gives -1. So IMHO the advange of above rewrite is 0.

By the way:  the performance is a probably better if you change
   m/$x/    into    m/$x/o

and the code is a bit nicer with qr//
   my $yearmonth_re = '(?:\d+Y)?(?:\d+M)?';
   my $yearmonth    = qr/(?:\d+Y)?(?:\d+M)?/;

-- 
Regards,

               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark at Overmeer.net                          solutions at overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net




More information about the Xml-compile mailing list