System/Passthrough.pm

filter: Statementstmt 83.3% 160 / 192 Branchbran 31.1% 28 / 90 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 95.0% 38 / 40 Podpod 100% 35 / 35 totaltotal 73.1% 261 / 357 CC 43 SCAR 8.9
CC
43
Cov
67%
child
3.2
copy
3.2
create
3.2
CRAP 2.4
« System/Table.pm ↑ Summary
1 package File::System::Passthrough;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.02';
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use base 'File::System::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 File::System::Passthrough - A file system module that delegates work to another
14  
15 =head1 SYNOPSIS
16  
17 package File::System::MyModule;
18  
19 use strict;
20 use base 'File::System::Passthrough';
21  
22 # You now have all methods available, just define those you must.
23  
24 =head1 DESCRIPTION
25  
26 This module is pretty useless on it's own. It simply delegates all the real work to an internal wrapped module. It shouldn't be used directly. However, I've found that many of the special modules written are used to wrap others and this provides the basic functionality.
27  
28 =head2 SUBCLASSING
29  
30 Basically, you can just declare L<File::System::Passthrough> as your base class and be done. You can define as many or few other methods as you prefer. You can refer to the wrapped class like so:
31  
32 sub my_method {
33 my $self = shift;
34 my $wrapped_fs = $self->{fs};
35  
36 # ...
37 }
38  
39 As of this writing, no other key in the C<$self> hash is used, so you can manipulate the other keys as you wish.
40  
41 =head2 ADDITIONAL API
42  
43 =over
44  
45 =item $obj = File::System-E<gt>new('Passthrough', $wrapped_obj)
46  
47 The constructor takes either a decendent of L<File::System::Object> or a reference to an array that can be used to construct such an object in C<$wrapped_obj>.
48  
49 =cut
50  
51 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
Pod documented
52 1 my $class = shift;
53 1 my $fs = shift;
54  
55 1 ▶ $fs = File::System->new(@$fs) if UNIVERSAL::isa($fs, 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($fs, "ARRAY") 1 0 1
56  
57 1 ▶ UNIVERSAL::isa($fs, 'File::System::Object')
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($fs, "File::System::Object") or croak("Wrapped object must be of type File::System::Object.") 1 0 1
58 or croak "Wrapped object must be of type File::System::Object.";
59  
60 1 return bless {
61 fs => $fs,
62 }, $class;
63 }
64  
65 1 my @plain = qw/
66 exists
67 is_creatable
68 is_valid
69 basename
70 dirname
71 path
72 is_root
73 properties
74 settable_properties
75 get_property
76 set_property
77 rename
78 move
79 remove
80 object_type
81 has_content
82 is_container
83 is_readable
84 is_seekable
85 is_writable
86 is_appendable
87 open
88 content
89 has_children
90 children_paths
91 /;
92  
93 1 my @wrap_if_defined = qw/
94 root
95 lookup
96 create
97 parent
98 copy
99 child
100 /;
101  
102 1 my @wrap_list = qw/
103 glob
104 children
105 /;
106  
107 1 for my $sub (@plain) {
108 0 ▶ eval <<EOF;
Subroutine basename: called CC=2 SCAR=8.4
Subroutine children_paths: called CC=2 SCAR=8.4
Subroutine content: called CC=2 SCAR=8.4
Subroutine dirname: called CC=2 SCAR=8.4
Subroutine exists: called CC=2 SCAR=8.4
Subroutine get_property: called CC=2 SCAR=8.4
Subroutine has_children: called CC=2 SCAR=8.4
Subroutine has_content: called CC=2 SCAR=8.4
Subroutine is_appendable: called CC=2 SCAR=8.4
Subroutine is_container: called CC=2 SCAR=8.4
Subroutine is_creatable: not called CC=2 SCAR=8.4
Subroutine is_readable: called CC=2 SCAR=8.4
Subroutine is_root: called CC=2 SCAR=8.4
Subroutine is_seekable: called CC=2 SCAR=8.4
Subroutine is_valid: called CC=2 SCAR=8.4
Subroutine is_writable: called CC=2 SCAR=8.4
Subroutine move: called CC=2 SCAR=8.4
Subroutine object_type: not called CC=2 SCAR=8.4
Subroutine open: called CC=2 SCAR=8.4
Subroutine path: called CC=2 SCAR=8.4
Subroutine properties: called CC=2 SCAR=8.4
Subroutine remove: called CC=2 SCAR=8.4
Subroutine rename: called CC=2 SCAR=8.4
Subroutine set_property: called CC=2 SCAR=8.4
Subroutine settable_properties: called CC=2 SCAR=8.4
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 25 branches
BranchTrueFalseTotal
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 20 88 108
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 72 72
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 48 16 64
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 48 48
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 32 32
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 48 48
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 144 144
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
109 sub $sub {
110 my \$self = shift;
111  
112 my \@args = map {
113 UNIVERSAL::isa(\$_, 'File::System::Passthrough') ?
114 \$_->{fs} : \$_
115 } \@_;
116  
117 return \$self->{fs}->$sub(\@args);
118 }
119 EOF
120  
121 25 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 25 25
122 }
123  
124 1 for my $sub (@wrap_if_defined) {
125 0 ▶ eval <<EOF;
Subroutine child: called CC=3 SCAR=11.6
Subroutine copy: called CC=3 SCAR=11.6
Subroutine create: called CC=3 SCAR=11.6
Subroutine lookup: called CC=3 SCAR=11.6
Subroutine parent: called CC=3 SCAR=11.6
Subroutine root: called CC=3 SCAR=11.6
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 12 branches
BranchTrueFalseTotal
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 22 22
if (defined $obj) { } 21 1 22
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 24 8 32
if (defined $obj) { } 24 0 24
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 96 96
if (defined $obj) { } 48 0 48
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 152 152
if (defined $obj) { } 152 0 152
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
if (defined $obj) { } 297 0 297
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
if (defined $obj) { } 10 0 10
126 sub $sub {
127 my \$self = shift;
128  
129 my \@args = map {
130 UNIVERSAL::isa(\$_, 'File::System::Passthrough') ?
131 \$_->{fs} : \$_
132 } \@_;
133  
134 my \$obj = \$self->{fs}->$sub(\@args);
135  
136 if (defined \$obj) {
137 return bless {
138 fs => \$obj,
139 }, ref \$self;
140 } else {
141 return undef;
142 }
143 }
144 EOF
145  
146 6 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 6 6
147 }
148  
149 1 for my $sub (@wrap_list) {
150 0 ▶ eval <<EOF;
Subroutine children: called CC=2 SCAR=7.3
Subroutine glob: called CC=2 SCAR=7.3
Pod documented
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 0 0
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 0 72 72
151 sub $sub {
152 my \$self = shift;
153  
154 my \@args = map {
155 UNIVERSAL::isa(\$_, 'File::System::Passthrough') ?
156 \$_->{fs} : \$_
157 } \@_;
158  
159 return map {
160 bless {
161 fs => \$_,
162 }, ref \$self;
163 } \$self->{fs}->$sub(\@args);
164 }
165 EOF
166  
167 2 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
168 }
169  
170 80 ▶sub find {
Subroutine find: called CC=2 SCAR=6.9
Pod documented
171 80 my $self = shift;
172 80 my $want = shift;
173  
174 362 ▶ my @args = (sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
175 362 my $file = shift;
176 362 return $want->(bless { fs => $file }, ref $self);
177 80 });
178  
179 push @args, map {
180 80 UNIVERSAL::isa($_, 'File::System::Passthrough') ?
181 36 ▶ $_->{fs} : $_
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_, 'File::System::Passthrough') ? : 36 0 36
182 } @_;
183  
184 return map {
185 76 bless {
186 fs => $_,
187 }, ref $self;
188 80 } $self->{fs}->find(@args);
189 }
190  
191 =back
192  
193 =head1 SEE ALSO
194  
195 L<File::System>, L<File::System::Object>
196  
197 =head1 AUTHOR
198  
199 Andrew Sterling Hanenkamp, E<lt>hanenkamp@users.sourceforge.netE<gt>
200  
201 =head1 COPYRIGHT AND LICENSE
202  
203 Copyright 2005 Andrew Sterling Hanenkamp. All Rights Reserved.
204  
205 This software is distributed and licensed under the same terms as Perl itself.
206  
207 =cut
208  
209 1 1
« System/Table.pm ↑ Summary