Tie::JCR - A tied hash interface for Java::JCR::Node


Tie-JCR documentation  | view source Contained in the Tie-JCR distribution.

Index


NAME

Top

Tie::JCR - A tied hash interface for Java::JCR::Node

SYNOPSIS

Top

  use Data::Dumper;
  use Java::JCR;
  use Java::JCR::Jackrabbit;
  use Tie::JCR;

  my $repository = Java::JCR::Jackrabbit->new;
  my $session = $respoitory->session;
  my $root_node = $session->get_root_node;
  tie my %root, 'Tie::JCR', $root_node;

  # Expensive, but we can dump the whole tree:
  print Dumper(\%root);

  my $type = $root{'jcr:primaryType'};
  my $uuid = $root{'jcr:uuid'};
  my $foo = $root{'foo'};
  my $nested_bar = $root{'qux'}{'baz'}{'bar'};

DESCRIPTION

Top

This provides a very simple, read-only interface to a node from Java::JCR. Each key represents the names of items within the node. Each value is either a scalar for non-multiple child properties, an array for multiple child properties, or nested hashes for child nodes. In the case of same-name children, you may see an array returned containing scalars and hashes for a mixture of properties and nodes.

CHANGES ARE TRANSIENT

Changes made to the tied hash are transient and only act to override the local cache. If you want to make changes to node, you must do so through the Java::JCR API. This is primarily meant as a convenience interface, not as a serious front-end to the JCR.

SUPPORTED OPERATIONS

The only hash operation that isn't implemented is CLEAR. Therefore, all of the following will work:

  tie my %hash, 'Tie::JCR', $node;
  my $value = $node{'property_name'};
  my $child_node = $node{'node_name'};

  # store a value temporarily IN THIS HASH ONLY, doesn't affect the JCR
  $node{'temp_value'} = 'blah';

  # make the property undefined IN THIS HASH ONLY, doesn't affect the JCR
  delete $node{'property_name'};

  # defined === exists since null values are not permitted in the JCR
  my $has_item = exists $node{'item_name'};

  my @keys = keys %node;
  my @values = values %node;
  while (my ($key, $value) = each %node) {
      print $key, " = ", $value, "\n";
  }

  # returns true if has_nodes or has_properties
  my $has_children = scalar %node;

CACHING

The fetch, store, and delete operations modify an internal cache. By using the cache, some speed can be gained by avoiding a second JCR API call. This is also how the store and delete operations make transient changes, by storing values in the cache.

INTERNAL METHODS

In addition, you can use the tied object to get the node back:

  my $node_obj = (tied %node)->node;

You may also wish to clear out any local changes used with store or otherwise held in the internal cache:

  (tied %node)->clear_cache;

JCR TYPES

The fetch operation handles all the various JCR types properly. Longs will be treated as longs, doubles as doubles, booleans as booleans, dates as dates, references as nodes, and everything else as a string.

AUTHOR

Top

Andrew Sterling Hanenkamp, <hanenkamp@cpan.org>

LICENSE AND COPYRIGHT

Top


Tie-JCR documentation  | view source Contained in the Tie-JCR distribution.