Data::Hive::PathPacker::Strict - a simple, strict path packer


Data-Hive documentation Contained in the Data-Hive distribution.

Index


Code Index:

NAME

Top

Data::Hive::PathPacker::Strict - a simple, strict path packer

VERSION

Top

version 1.008

DESCRIPTION

Top

The Strict path packer is the simplest useful implementation of Data::Hive::PathPacker. It joins path parts together with a fixed string and splits them apart on the same string. If the fixed string occurs any path part, an exception is thrown.

METHODS

Top

new

  my $packer = Data::Hive::PathPacker::Strict->new( \%arg );

The only valid argument is separator, which is the string used to join path parts. It defaults to a single period.

AUTHORS

Top

COPYRIGHT AND LICENSE

Top


Data-Hive documentation Contained in the Data-Hive distribution.

use strict;
use warnings;
package Data::Hive::PathPacker::Strict;
BEGIN {
  $Data::Hive::PathPacker::Strict::VERSION = '1.008';
}
use base 'Data::Hive::PathPacker';
# ABSTRACT: a simple, strict path packer

use Carp ();


sub new {
  my ($class, $arg) = @_;
  $arg ||= {};

  my $guts = {
    separator => $arg->{separator} || '.',
  };

  return bless $guts => $class;
}

sub pack_path {
  my ($self, $path) = @_;

  my $sep     = $self->{separator};
  my @illegal = grep { /\Q$sep\E/ } @$path;

  Carp::confess("illegal hive path parts: @illegal") if @illegal;

  return join $sep, @$path;
}

sub unpack_path {
  my ($self, $str) = @_;

  my $sep = $self->{separator};
  return [ split /\Q$sep\E/, $str ];
}

1;

__END__