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   20 use strict;
  4         8  
  4         113  
2 4     4   19 use warnings;
  4         23  
  4         249  
3             package Data::Hive::PathPacker::Strict;
4             # ABSTRACT: a simple, strict path packer
5             $Data::Hive::PathPacker::Strict::VERSION = '1.013';
6 4     4   19 use parent 'Data::Hive::PathPacker';
  4         6  
  4         27  
7              
8 4     4   168 use Carp ();
  4         9  
  4         950  
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 28 my ($class, $arg) = @_;
28 16   50     72 $arg ||= {};
29              
30             my $guts = {
31 16   50     78 separator => $arg->{separator} || '.',
32             };
33              
34 16         102 return bless $guts => $class;
35             }
36              
37             sub pack_path {
38 161     161 1 210 my ($self, $path) = @_;
39              
40 161         251 my $sep = $self->{separator};
41 161         233 my @illegal = grep { /\Q$sep\E/ } @$path;
  363         1036  
42              
43 161 100       551 Carp::confess("illegal hive path parts: @illegal") if @illegal;
44              
45 160         797 return join $sep, @$path;
46             }
47              
48             sub unpack_path {
49 266     266 1 381 my ($self, $str) = @_;
50              
51 266         374 my $sep = $self->{separator};
52 266         1095 return [ split /\Q$sep\E/, $str ];
53             }
54              
55             1;
56              
57             __END__