File Coverage

blib/lib/Data/Hive/PathPacker/Strict.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition 2 4 50.0
subroutine 7 7 100.0
pod 3 3 100.0
total 39 41 95.1


line stmt bran cond sub pod time code
1 4     4   25 use strict;
  4         7  
  4         108  
2 4     4   16 use warnings;
  4         6  
  4         160  
3             package Data::Hive::PathPacker::Strict 1.015;
4             # ABSTRACT: a simple, strict path packer
5              
6 4     4   18 use parent 'Data::Hive::PathPacker';
  4         7  
  4         22  
7              
8 4     4   162 use Carp ();
  4         7  
  4         756  
9              
10             #pod =head1 DESCRIPTION
11             #pod
12             #pod The Strict path packer is the simplest useful implementation of
13             #pod L. It joins path parts together with a fixed string
14             #pod and splits them apart on the same string. If the fixed string occurs any path
15             #pod part, an exception is thrown.
16             #pod
17             #pod =method new
18             #pod
19             #pod my $packer = Data::Hive::PathPacker::Strict->new( \%arg );
20             #pod
21             #pod The only valid argument is C, which is the string used to join path
22             #pod parts. It defaults to a single period.
23             #pod
24             #pod =cut
25              
26             sub new {
27 16     16 1 32 my ($class, $arg) = @_;
28 16   50     66 $arg ||= {};
29              
30             my $guts = {
31 16   50     63 separator => $arg->{separator} || '.',
32             };
33              
34 16         93 return bless $guts => $class;
35             }
36              
37             sub pack_path {
38 161     161 1 220 my ($self, $path) = @_;
39              
40 161         248 my $sep = $self->{separator};
41 161         222 my @illegal = grep { /\Q$sep\E/ } @$path;
  363         1000  
42              
43 161 100       486 Carp::confess("illegal hive path parts: @illegal") if @illegal;
44              
45 160         631 return join $sep, @$path;
46             }
47              
48             sub unpack_path {
49 266     266 1 359 my ($self, $str) = @_;
50              
51 266         329 my $sep = $self->{separator};
52 266         796 return [ split /\Q$sep\E/, $str ];
53             }
54              
55             1;
56              
57             __END__