File Coverage

blib/lib/HTML/FormFu/Deflator/PathClassFile.pm
Criterion Covered Total %
statement 16 17 94.1
branch 11 14 78.5
condition 6 6 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 37 42 88.1


line stmt bran cond sub pod time code
1             package HTML::FormFu::Deflator::PathClassFile;
2              
3 2     2   499 use strict;
  2         3  
  2         80  
4             our $VERSION = '2.05'; # VERSION
5              
6 2     2   7 use Moose;
  2         2  
  2         12  
7 2     2   8014 use MooseX::Attribute::FormFuChained;
  2         3  
  2         347  
8             extends 'HTML::FormFu::Deflator';
9              
10             has relative => ( is => 'rw', traits => ['FormFuChained'] );
11             has absolute => ( is => 'rw', traits => ['FormFuChained'] );
12             has basename => ( is => 'rw', traits => ['FormFuChained'] );
13              
14             sub deflator {
15 4     4 0 4 my ( $self, $value ) = @_;
16 4 50       7 return $value unless ( ref $value );
17              
18             # we default to relative(1)
19 4 100 100     101 $self->relative(1)
      100        
20             unless ( $self->absolute || $self->basename || $self->relative );
21              
22 4 100       93 if ( $self->relative ) {
    100          
    50          
23 2 100       45 return $value->relative(
24             $self->relative eq "1" ? undef : $self->relative )->stringify;
25             }
26             elsif ( $self->absolute ) {
27 1 50       25 return $value->absolute(
28             $self->absolute eq "1" ? undef : $self->absolute )->stringify;
29             }
30             elsif ( $self->basename ) {
31 1         3 return $value->basename;
32             }
33              
34             # fallback, should never happen
35 0           return $value->stringify;
36             }
37              
38             __PACKAGE__->meta->make_immutable;
39              
40             1;
41              
42             __END__
43              
44             =head1 NAME
45              
46             HTML::FormFu::Deflator::PathClassFile - Deflator for Path::Class::File objects
47              
48             =head1 VERSION
49              
50             version 2.05
51              
52             =head1 SYNOPSIS
53              
54             $form->deflator( PathClassFile => 'file' )
55             ->relative( 'root' );
56              
57             ---
58             elements:
59             - type: Text
60             deflator:
61             - type: PathClassFile
62             relative: root
63              
64             =head1 DESCRIPTION
65              
66             Deflator for Path::Class::File objects.
67              
68             There are three types of deflation:
69              
70             =over
71              
72             =item relative
73              
74             Set this to 1 to deflate to a relative path. Anything else than 1 specifies the
75             directory to use as the base of relativity - otherwise the current working
76             directory will be used.
77              
78             =item absolute
79              
80             Set this to 1 to deflate to an absolute path. Anything else than 1 specifies the
81             directory to use as the base of relativity - otherwise the current working
82             directory will be used.
83              
84             =item basename
85              
86             Set this to 1 to get the name of the file without the directory portion.
87              
88             =back
89              
90             As you cannot set values for a File element, this deflator will only work
91             on regular form elements.
92              
93              
94             =head1 AUTHOR
95              
96             Moritz Onken, C<onken@houseofdesign.de>
97              
98             =head1 LICENSE
99              
100             This library is free software, you can redistribute it and/or modify it under
101             the same terms as Perl itself.
102              
103             =cut