File Coverage

blib/lib/String/Incremental/String.pm
Criterion Covered Total %
statement 34 35 97.1
branch 4 4 100.0
condition n/a
subroutine 9 10 90.0
pod 2 3 66.6
total 49 52 94.2


line stmt bran cond sub pod time code
1             package String::Incremental::String;
2 18     18   168420 use 5.008005;
  18         67  
  18         1238  
3 18     18   447 use warnings;
  18         33  
  18         614  
4 18     18   4877 use Mouse;
  18         174219  
  18         328  
5 18     18   10593 use Data::Validator;
  18         15084  
  18         609  
6 18     18   3120 use MouseX::Types::Mouse qw( Str CodeRef is_CodeRef );
  18         7357  
  18         326  
7              
8             use overload (
9             '""' => \&as_string,
10 0     0   0 '=' => sub { $_[0] },
11 18     18   12777 );
  18         3433  
  18         248  
12              
13             has 'format' => ( is => 'ro', isa => Str );
14             has 'value' => ( is => 'ro', isa => CodeRef|Str );
15              
16             sub BUILDARGS {
17 61     61 1 85351 my ($class, %args) = @_;
18 61         216 my $v = Data::Validator->new(
19             format => { isa => Str },
20             value => { isa => CodeRef|Str },
21             );
22 61         11498 %args = %{$v->validate( \%args )};
  61         218  
23 57         3556 return \%args;
24             }
25              
26             sub as_string {
27 90     90 1 267 my ($self) = @_;
28 90         226 my $val = $self->value;
29 90 100       304 if ( is_CodeRef( $val ) ) { $val = $val->() }
  2         7  
30 90         972 return sprintf( $self->format, $val );
31             }
32              
33             sub re {
34 53     53 0 227 my ($self) = @_;
35 53         64 my $re;
36 53 100       247 if ( is_CodeRef( $self->value ) ) {
37 1         2 $re = '.*?'; # tmp
38             }
39             else {
40 52         1595 $re = "$self";
41             }
42              
43 53         687 return qr/$re/;
44             }
45              
46             __PACKAGE__->meta->make_immutable();
47             __END__