Changeset 1706

Show
Ignore:
Timestamp:
01/09/06 14:12:25
Author:
miyagawa
Message:

JSONize syck parser

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • JSON-Syck/trunk/Changes

    r1705 r1706  
    1 [Changes for 0.10 - 2006-01-09] 
     1Revision history for JSON::Syck 
    22 
    3 * Fix emitting of empty strings; they are now always quoted. 
    4   Reported by: Chia-Liang Kao 
    5  
    6 [Changes for 0.09 - 2006-01-09] 
    7  
    8 * Downgrade to the last stable release of libsyck to fix the 
    9   hash dumping layout problem. 
    10   Reported by: Gaal Yahas 
    11  
    12 [Changes for 0.08 - 2006-01-09] 
    13  
    14 * Fix double-free problem in object dumping. 
    15   Reported by: Chia-Liang Kao 
    16  
    17 [Changes for 0.07 - 2006-01-09] 
    18  
    19 * Loading of blessed hash and array references. 
    20  
    21 * Do away with Test::More as testing dependency. 
    22  
    23 [Changes for 0.06 - 2006-01-08] 
    24  
    25 * Fix building problems on case-insensitive filesystems. 
    26   Reported by: Chia-Liang Kao 
    27  
    28 [Changes for 0.05 - 2006-01-08] 
    29  
    30 * DumpFile() and LoadFile() is exported by default. 
    31  
    32 * Undef now dumps as '~'; also supports dumping blessed references as 
    33   'perl/!type'.  (Loading them doesn't work at this moment.) 
    34   Implemented by: Gaal Yahas 
    35  
    36 * Loading hashes and arrays no longer creates dangling references 
    37   that caused memory leaks. 
    38   Reported by: Tatsuhiko Miyagawa 
    39  
    40 [Changes for 0.04 - 2005-12-28] 
    41  
    42 * Truly support Perl versions before 5.7.3, thanks to ppport.h. 
    43   Reported by: Anton Berezin 
    44  
    45 [Changes for 0.03 - 2005-12-27] 
    46  
    47 * Make syck.h compile with a Perl built with -DDEBUG. 
    48   Reported by: Slaven Rezic 
    49  
    50 [Changes for 0.02 - 2005-12-26] 
    51  
    52 * Move from SWIG to much lighter-weight native XS implementation. 
    53  
    54 * Begins bundling Storable.xs to use the same serialization logic. 
    55  
    56 [Changes for 0.01 - 2005-12-26] 
    57  
    58 * Initial release to CPAN of this six-hours-old hack. 
     30.01 
     4        * Initial release, copied from Audrey Tang's YAML-Syck distro 
  • JSON-Syck/trunk/MANIFEST

    r1705 r1706  
    1616inc/Module/Install/Win32.pm 
    1717inc/Module/Install/WriteAll.pm 
    18 lib/YAML/Dumper/Syck.pm 
    19 lib/YAML/Loader/Syck.pm 
    20 lib/YAML/Syck.pm 
    21 lib/YAML/Syck.pod 
     18lib/JSON/Syck.pm 
    2219Makefile.PL 
    2320MANIFEST                        This list of files 
     
    2724README 
    2825Storable.xs 
    29 syck_.c 
    3026syck.h 
    3127Syck.xs 
     28syck_.c 
    3229syck_st.c 
    3330syck_st.h 
    34 t/1-basic.t 
    35 t/2-scalars.t 
    36 t/3-objects.t 
     31t/00_use.t 
    3732token.c 
    3833yaml2byte.c 
  • JSON-Syck/trunk/Makefile.PL

    r1705 r1706  
    22use inc::Module::Install 0.48; 
    33 
    4 name        'YAML-Syck'; 
    5 all_from    'lib/YAML/Syck.pm'; 
     4name        'JSON-Syck'; 
     5all_from    'lib/JSON/Syck.pm'; 
    66inc_paths   '.'; 
    77c_files     (glob("*.c"), (-e 'Syck.c' ? () : 'Syck.c')); 
     
    99can_cc or die "This module requires a C compiler"; 
    1010 
    11 sign; WriteAll; 
     11WriteAll; 
  • JSON-Syck/trunk/Syck.xs

    r1705 r1706  
    103103 
    104104    if (sv == &PL_sv_undef) { 
    105         return syck_emit_scalar(e, "string", scalar_none, 0, 0, 0, "~", 1); 
     105        return syck_emit_scalar(e, "string", scalar_2quote, 0, 0, 0, "~", 1); 
    106106    } 
    107107     
     
    132132        case SVt_PVNV: { 
    133133            if (SvCUR(sv) > 0) { 
    134                 syck_emit_scalar(e, OBJOF("string"), scalar_none, 0, 0, 0, SvPVX(sv), SvCUR(sv)); 
     134                syck_emit_scalar(e, OBJOF("string"), scalar_2quote, 0, 0, 0, SvPVX(sv), SvCUR(sv)); 
    135135            } 
    136136            else { 
     
    145145        case SVt_PVLV: { 
    146146            if (sv_len(sv) > 0) { 
    147                 syck_emit_scalar(e, OBJOF("string"), scalar_none, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 
     147                syck_emit_scalar(e, OBJOF("string"), scalar_2quote, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 
    148148            } 
    149149            else { 
     
    193193        case SVt_PVCV: { 
    194194            /* XXX TODO XXX */ 
    195             syck_emit_scalar(e, OBJOF("string"), scalar_none, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 
     195            syck_emit_scalar(e, OBJOF("string"), scalar_2quote, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 
    196196            break; 
    197197        } 
     
    199199        case SVt_PVFM: { 
    200200            /* XXX TODO XXX */ 
    201             syck_emit_scalar(e, OBJOF("string"), scalar_none, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 
     201            syck_emit_scalar(e, OBJOF("string"), scalar_2quote, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 
    202202            break; 
    203203        } 
    204204        case SVt_PVIO: { 
    205             syck_emit_scalar(e, OBJOF("string"), scalar_none, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 
     205            syck_emit_scalar(e, OBJOF("string"), scalar_2quote, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 
    206206            break; 
    207207        } 
     
    216216    SV* out = newSVpvn("", 0); 
    217217    SyckEmitter *emitter = syck_new_emitter(); 
     218    emitter->headless = 1; 
    218219 
    219220    bonus = emitter->bonus = S_ALLOC_N(struct emitter_xtra, 1); 
     
    232233} 
    233234 
    234 MODULE = YAML::Syck            PACKAGE = YAML::Syck            
     235MODULE = JSON::Syck            PACKAGE = JSON::Syck            
    235236 
    236237PROTOTYPES: DISABLE 
  • JSON-Syck/trunk/lib/JSON/Syck.pm

    r1705 r1706  
    1 package YAML::Syck; 
     1package JSON::Syck; 
    22use strict; 
    3 use vars qw( @ISA @EXPORT $VERSION ); 
    43 
    5 use 5.003
     4use Exporter
    65use DynaLoader; 
    76 
    8 $VERSION = '0.10'; 
    9 @EXPORT  = qw( Dump Load DumpFile LoadFile ); 
    10 @ISA     = qw( Exporter DynaLoader ); 
    11  
    12 sub DumpFile { 
    13     my $file = shift; 
    14     local *FH; 
    15     open FH, "> $file" or die "Cannot write to $file: $!"; 
    16     print FH Dump($_[0]); 
    17 
    18 sub LoadFile { 
    19     my $file = shift; 
    20     local *FH; 
    21     open FH, "< $file" or die "Cannot read from $file: $!"; 
    22     Load(do { local $/; <FH> }) 
    23 
     7our $VERSION = '0.01'; 
     8our @EXPORT_OK  = qw( Dump Load ); 
     9our @ISA     = qw( Exporter DynaLoader ); 
    2410 
    2511__PACKAGE__->bootstrap; 
    2612 
    27131; 
     14 
     15__END__ 
     16 
     17=head1 NAME 
     18 
     19JSON::Syck - JSON is YAML 
     20 
     21=head1 SYNOPSIS 
     22 
     23  use JSON::Syck; 
     24 
     25  my $data = JSON::Syck::Load($json); 
     26  my $json = JSON::Syck::Dump($data); 
     27 
     28=head1 DESCRIPTION 
     29 
     30JSON::Syck is a syck implementatoin of JSON parsing and 
     31generation. Because JSON is YAML 
     32(L<http://redhanded.hobix.com/inspect/yamlIsJson.html>), using syck 
     33gives you the fastest and most memory efficient parser and dumper for 
     34JSON data representation. 
     35 
     36=head1 DIFFERENCE WITH JSON 
     37 
     38You might want to know the difference between I<JSON> and 
     39I<JSON::Syck>. 
     40 
     41While JSON is a pure-perl module and JSON::Syck is based on libsyck, 
     42JSON::Syck is supposed to be very fast and memory efficient. See 
     43chansen's benchmark table at L<http://rafb.net/paste/results/8rSJGq74.txt>. 
     44 
     45JSON.pm comes with dozens of ways to do the same thing and lots of 
     46options, while JSON::Syck doesn't. 
     47 
     48JSON::Syck doesn't use camelCase method names :-) 
     49 
     50=head1 BUGS 
     51 
     52C<Load> function in JSON::Syck is actually the same with that of 
     53YAML's. That means, when you give a valid YAML but non-valid JSON 
     54data, it just accepts and is able to parse the string. 
     55 
     56=head1 AUTHOR 
     57 
     58Tatsuhiko Miyagawa E<lt>miyagawa@gmail.comE<gt> 
     59 
     60This module is forked from Audrey Tang's excellent YAML::Syck module 
     61and 99% of the XS code is written by Audrey. 
     62 
     63The F<libsyck> code bundled with this module is written by I<why the 
     64lucky stiff>, under a BSD-style license.  See the F<COPYING> file for 
     65details. 
     66 
     67The F<Storable.xs> code bundled with this library is written by 
     68Raphael Manfredi and maintained by perl5-porters, under the same 
     69license as Perl. 
     70 
     71This program is free software; you can redistribute it and/or modify 
     72it under the same terms as Perl itself. 
     73 
     74=cut