AnyData

 view release on metacpan or  search on metacpan

lib/AnyData.pm  view on Meta::CPAN


  This uses the XML format to parse the supplied string and returns a tied
  hash to the resulting table.


  my $table = adTie( 'ARRAY', [['id','motto'],['perl','TIMTOWTDI']] );

  This uses the column names "id" and "motto" and the supplied row values
  and returns a tied hash to the resulting table.

It is also possible to use an empty array to create a new empty tied hash in any format, for example:

  my $table = adTie('XML',[],'c');

  creates a new empty tied hash;

See adConvert() and adExport() for further examples of using strings and arrays.

=head2 Ties, Flocks, I/O, and Atomicity

AnyData provides flocking which works under the limitations of flock -- that it only works if other processes accessing the files are also using flock and only on platforms that support flock.  See the flock() man page for details.

Here is what the user supplied open modes actually do:

 r = read only  (LOCK_SH)  O_RDONLY
 u = update     (LOCK_EX)  O_RDWR
 c = create     (LOCK_EX)  O_CREAT | O_RDWR | O_EXCL
 o = overwrite  (LOCK_EX)  O_CREAT | O_RDWR | O_TRUNC

When you use something like "my $table = adTie(...)", it opens
the file with a lock and leaves the file and lock open until
1) the hash variable ($table) goes out of scope or 2) the
hash is undefined (e.g. "undef $table") or 3) the hash is
re-assigned to another tie.  In all cases the file is closed
and the lock released.

If adTie is called without creating a tied hash variable, the file
is closed and the lock released immediately after the call to adTie.

 For example:  print adTie('XML','foo.xml')->{main_office}->{phone}.

 That obtains a shared lock, opens the file, retrieves the one value
 requested, closes the file and releases the lock.

These two examples accomplish the same thing but the first example
opens the file once, does all of the deletions, keeping the exclusive
lock in place until they are all done, then closes the
file.  The second example opens and closes the file three times,
once for each deletion and releases the exclusive lock between each
deletion:

 1. my $t = adTie('Pipe','games.db','u');
    delete $t->{"user$_"} for (0..3);
    undef $t; # closes file and releases lock

 2. delete adTie('Pipe','games.db','u')->{"user$_"} for (0..3);
    # no undef needed since no hash variable created

=head2 Deletions and Packing

In order to save time and to prevent having to do writes anywhere except at the end of the file, deletions and updates are *not* done at the time of issuing a delete command.  Rather when the user does a delete, the position of the deleted record is ...

=head1 MORE HELP

See the README file and the test.pl included with the module
for further examples.

See the AnyData/Format/*.pm PODs for further details of specific
formats.

For further support, please use comp.lang.perl.modules

=head1 ACKNOWLEDGEMENTS

Special thanks to Andy Duncan, Tom Lowery, Randal Schwartz, Michel Rodriguez, Jochen Wiedmann, Tim Bunce, Alligator Descartes, Mathew Persico, Chris Nandor, Malcom Cook and to many others on the DBI mailing lists and the clp* newsgroups.

=head1 AUTHOR & COPYRIGHT

 Jeff Zucker <jeff@vpservices.com>

 This module is copyright (c), 2000 by Jeff Zucker.
 Some changes (c) 2012 Sven Dowideit L<mailto:SvenDowideit@fosiki.com>
 It may be freely distributed under the same terms as Perl itself.

=cut

################################
# END OF AnyData
################################
1;



( run in 0.511 second using v1.01-cache-2.11-cpan-39bf76dae61 )