ie/File/Indexed/JSON.pm
## Author: Bryan Jurish <moocow@cpan.org>
## Description: tied array access to indexed data files: JSON-encoded data structures
package Tie::File::Indexed::JSON;
use Tie::File
)
## $tfi = CLASS->new($file,%opts)
## + new %opts, object structure:
## (
## json => $json, ##-- JSON object or HASH-ref of options
## )
## \%defaults = CLASS_OR_OBJECT->defaults()
#
# + default attributes for constructor
sub defaults {
return (
$_[0]->SUPER::defaults,
json => {utf8=>1, relaxed=>1, allow_nonref=>1, allow_unknown=>1, allow_blessed=>1, convert_blessed=>1, p
::Indexed
base class.
=head2 In-place item modification not supported
See L<Tie::File::Indexed::JSON/"In-place item modification not supported"> for details.
=head2 Limited datatype support
See L<
::Indexed
base class.
=head2 In-place item modification not supported
See L<Tie::File::Indexed::JSON/"In-place item modification not supported"> for details.
=head2 Limited datatype support
See L<
exed data files
package Tie::File::Indexed;
use 5.10.0; ##-- for // operator
use Tie::Array;
use JSON qw();
use Fcntl qw(:DEFAULT :seek :flock);
use File::Copy qw();
use IO::File;
use Carp qw(confess
: JSON
## $data = CLASS->loadJsonString( $string,%opts)
## $data = CLASS->loadJsonString(\$string,%opts)
## + %opts passed to JSON::from_json(), e.g. (relaxed=>0)
## + supports $opts{json} = $json_
obj
sub loadJsonString {
my $that = UNIVERSAL::isa($_[0],__PACKAGE__) ? shift : __PACKAGE__;
my $bufr = ref($_[0]) ? $_[0] : \$_[0];
my %opts = @_[1..$#_];
return $opts{json}->decode($$bufr) i
::Indexed
base class.
=head2 In-place item modification not supported
See L<Tie::File::Indexed::JSON/"In-place item modification not supported"> for details.
=head2 Limited datatype support
Only r
==========================
## NAME
=pod
=head1 NAME
Tie::File::Indexed::JSON - tied array access to indexed data files: JSON-encoded data structures
=cut
##========================================
================
## SYNOPSIS
=pod
=head1 SYNOPSIS
use Tie::File::Indexed::JSON;
tie(my @data, 'Tie::File::Indexed::JSON', $filename, %options) or die ...
$data[0] = {foo=>'bar'}; # transparentl
1 DESCRIPTION
Tie::File::Indexed::JSON provides a
L<Tie::File::Indexed|Tie::File::Indexed> subclass for
storing arrays of perl data structures encoded using the JSON module.
=cut
##----------------
::Indexed
base class.
=head2 In-place item modification not supported
See L<Tie::File::Indexed::JSON/"In-place item modification not supported"> for details.
=head2 Limited datatype support
See L<
parent encoding/decoding of UTF8-encoded strings,
and complex data structures encoded via the L<JSON|JSON> or L<Storable|Storable>
modules. See L</SUBCLASSES> for details.
=cut
##-------------------
between incompatible file formats
(e.g. Storable and JSON), but it should be faster than array assignment:
tie(my @a, 'Tie::File::Indexed::JSON', 'a.tfx');
tie(my @b, 'Tie::File::Indexed::Stor
# ... but this ought to
tie(my @a2, 'Tie::File::Indexed::JSON', 'a2.tfx');
@a2 = @a; # slow element-wise copy