Jifty/Util.pm

filter: Statementstmt 40.7% 62 / 152 Branchbran 21.2% 14 / 66 Conditioncond 7.5% 4 / 53 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 50.0% 11 / 22 Podpod 100% 14 / 14 totaltotal 31.2% 105 / 336 CC 56 SCAR 36.3
CC
56
Cov
30%
share_root
110.0
canonicalize_path
72.0
stringify
56.0
CRAP 37.7
« Jifty/Plugin/REST/Dispatcher.pm ↑ Summary Jifty/Web/Form/Field/OrderedList.pm »
1 113 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 113 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Jifty::Util;
5  
6 =head1 NAME
7  
8 Jifty::Util - Things that don't fit anywhere else
9  
10 =head1 DESCRIPTION
11  
12  
13 =cut
14  
15 113 ▶use Jifty ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use File::ShareDir ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 6 ▶use vars qw/%ABSOLUTE_PATH $JIFTY_ROOT $SHARE_ROOT $APP_ROOT/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 =head2 absolute_path PATH
24  
25 C<absolute_path> converts PATH into an absolute path, relative to the
26 application's root (as determined by L</app_root>) This can be called
27 as an object or class method.
28  
29 =cut
30  
31 0 ▶sub absolute_path {
Subroutine absolute_path: not called CC=3 SCAR=24.8
Pod documented
32 0 my $self = shift;
33 0 ▶ my $path = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
34  
35  
36 0 ▶ return $ABSOLUTE_PATH{$path} if (exists $ABSOLUTE_PATH{$path});
Branch: 1 branch
BranchTrueFalseTotal
if exists $Jifty::Util::ABSOLUTE_PATH{$path} 0 0 0
37 0 $path = $self->canonicalize_path($path);
38 0 return $ABSOLUTE_PATH{$path} = File::Spec->rel2abs($path , Jifty::Util->app_root);
39 }
40  
41  
42 =head2 canonicalize_path PATH
43  
44 Takes a "path" style /foo/bar/baz and returns a canonicalized (but not necessarily absolute)
45 version of the path. Always use C</> as the separator, even on platforms which recognizes
46 both C</> and C<\> as valid separators in PATH.
47  
48 =cut
49  
50 0 ▶sub canonicalize_path {
Subroutine canonicalize_path: not called CC=8 SCAR=42.8
Pod documented
51 0 my $self = shift;
52 0 my $path = shift;
53 0 my $keepempty = shift;
54  
55 0 my @path = File::Spec->splitdir($path);
56  
57 0 my @newpath;
58  
59 0 for (@path) {
60 # If we have an empty part and it's not the root, skip it.
61 0 ▶ if ( @newpath and ($_ =~ /^(?:\.|)$/)) {
Branch: 2 branches
BranchTrueFalseTotal
if (@newpath and $_ =~ /^(?:\.|)$/) { } 0 0 0
elsif ($_ ne '..') { } 0 0 0
Condition0%0/3
@newpath and $_ =~ /^(?:\.|)$/
!ll&&!rl&&r
000
MC/DC0%0/2
@newpath and $_ =~ /^(?:\.|)$/
@newpath $_ =~ /^(?:\.|)$/
Truth table0%0/3
A and B
A= @newpathB= $_ =~ /^(?:\.|)$/
ABresult
0X0
100
111
62 0 next;
63 }
64 elsif( $_ ne '..') {
65 0 push @newpath, $_ ;
66 } else {
67 0 pop @newpath;
68 }
69 }
70  
71 0 ▶ push @newpath, '' if $keepempty and @path and $path[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $keepempty and @path and $path[-1] eq "" 0 0 0
Condition0%0/6
$keepempty and @path and $path[-1] eq ""
!ll&&!rl&&r
000
$keepempty and @path
!ll&&!rl&&r
000
MC/DC0%0/3
$keepempty and @path and $path[-1] eq ""
$keepempty @path $path[-1] eq ""
Truth table0%0/4
A and B and C
A= $keepemptyB= @pathC= $path[-1] eq ""
ABCresult
0XX0
10X0
1100
1111
72 0 return join("/",@newpath);
73 }
74  
75  
76 =head2 jifty_root
77  
78 Returns the root directory that Jifty has been installed into.
79 Uses %INC to figure out where Jifty.pm is.
80  
81 =cut
82  
83 0 ▶sub jifty_root {
Subroutine jifty_root: not called CC=2 SCAR=17.9
Pod documented
84 0 my $self = shift;
85 0 ▶ unless ($JIFTY_ROOT) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Jifty::Util::JIFTY_ROOT) 0 0 0
86 0 my ($vol,$dir,$file) = File::Spec->splitpath($INC{"Jifty.pm"});
87 0 $JIFTY_ROOT = File::Spec->rel2abs("$vol$dir");
88 }
89 0 return ($JIFTY_ROOT);
90 }
91  
92  
93 =head2 share_root
94  
95 Returns the 'share' directory of the installed Jifty module. This is
96 currently only used to store the common Mason components, CSS, and JS
97 of Jifty and it's plugins.
98  
99 =cut
100  
101 0 ▶sub share_root {
Subroutine share_root: not called CC=10 SCAR=47.0
Pod documented
102 0 my $self = shift;
103 0 ▶ unless (defined $SHARE_ROOT) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Jifty::Util::SHARE_ROOT) 0 0 0
104 # Try for the local version, first
105 0 my @root = File::Spec->splitdir($self->jifty_root); # lib
106 0 pop @root; # Jifty-version
107 0 $SHARE_ROOT = File::Spec->catdir(@root,"share");
108 0 ▶ undef $SHARE_ROOT unless defined $SHARE_ROOT and -d $SHARE_ROOT and -d File::Spec->catdir($SHARE_ROOT,"web");
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Jifty::Util::SHARE_ROOT and -d $Jifty::Util::SHARE_ROOT and -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web") 0 0 0
Condition0%0/6
defined $Jifty::Util::SHARE_ROOT and -d $Jifty::Util::SHARE_ROOT and -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web")
!ll&&!rl&&r
000
defined $Jifty::Util::SHARE_ROOT and -d $Jifty::Util::SHARE_ROOT
!ll&&!rl&&r
000
MC/DC0%0/3
defined $Jifty::Util::SHARE_ROOT and -d $Jifty::Util::SHARE_ROOT and -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web")
defined $Jifty::Util::SHARE_ROOT -d $Jifty::Util::SHARE_ROOT -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web")
Truth table0%0/4
A and B and C
A= defined $Jifty::Util::SHARE_ROOTB= -d $Jifty::Util::SHARE_ROOTC= -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web")
ABCresult
0XX0
10X0
1100
1111
109  
110 # If that doesn't pass inspection, try File::ShareDir::dist_dir
111 0 ▶ $SHARE_ROOT ||= eval { File::Spec->rel2abs( File::ShareDir::dist_dir('Jifty') )};
Condition0%0/3
$Jifty::Util::SHARE_ROOT ||= eval { do { "File::Spec"->rel2abs(File::ShareDir::dist_dir("Jifty")) } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$Jifty::Util::SHARE_ROOT ||= eval { do { "File::Spec"->rel2abs(File::ShareDir::dist_dir("Jifty")) } }
$Jifty::Util::SHARE_ROOT eval { do { "File::Spec"->rel2abs(File::ShareDir::dist_dir("Jifty")) } }
Truth table0%0/3
A ||= B
A= $Jifty::Util::SHARE_ROOTB= eval { do { "File::Spec"->rel2abs(File::ShareDir::dist_dir("Jifty")) } }
ABresult
1X1
011
000
112 0 ▶ undef $SHARE_ROOT unless defined $SHARE_ROOT and -d $SHARE_ROOT and -d File::Spec->catdir($SHARE_ROOT,"web");
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Jifty::Util::SHARE_ROOT and -d $Jifty::Util::SHARE_ROOT and -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web") 0 0 0
Condition0%0/6
defined $Jifty::Util::SHARE_ROOT and -d $Jifty::Util::SHARE_ROOT and -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web")
!ll&&!rl&&r
000
defined $Jifty::Util::SHARE_ROOT and -d $Jifty::Util::SHARE_ROOT
!ll&&!rl&&r
000
MC/DC0%0/3
defined $Jifty::Util::SHARE_ROOT and -d $Jifty::Util::SHARE_ROOT and -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web")
defined $Jifty::Util::SHARE_ROOT -d $Jifty::Util::SHARE_ROOT -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web")
Truth table0%0/4
A and B and C
A= defined $Jifty::Util::SHARE_ROOTB= -d $Jifty::Util::SHARE_ROOTC= -d "File::Spec"->catdir($Jifty::Util::SHARE_ROOT, "web")
ABCresult
0XX0
10X0
1100
1111
113 }
114  
115 0 ▶ die "Can't locate Jifty share root!" unless defined $SHARE_ROOT;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Jifty::Util::SHARE_ROOT 0 0 0
116 0 return ($SHARE_ROOT);
117 }
118  
119 =head2 app_root
120  
121 Returns the application's root path. This is done by returning
122 $ENV{'JIFTY_APP_ROOT'} if it exists. If not, Jifty tries searching
123 upward from the current directory, looking for a directory which
124 contains a C<bin/jifty>. Failing that, it searches upward from
125 wherever the executable was found.
126  
127 It C<die>s if it can only find C</usr> or C</usr/local> which fit
128 these criteria.
129  
130 =cut
131  
132 1 ▶sub app_root {
Subroutine app_root: called CC=13 SCAR=32.3
Pod documented
133 1 my $self = shift;
134 1 my %args = @_;
135  
136 1 ▶ return $ENV{'JIFTY_APP_ROOT'} if ($ENV{'JIFTY_APP_ROOT'});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"JIFTY_APP_ROOT"} 0 1 1
137 1 ▶ return $APP_ROOT if ($APP_ROOT);
Branch: 1 branch
BranchTrueFalseTotal
if $Jifty::Util::APP_ROOT 0 1 1
138
139 1 my @roots;
140  
141 1 push( @roots, Cwd::cwd() );
142  
143 1 eval { Jifty::Util->require('FindBin') };
144 1 ▶ if ( my $err = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) { } 0 1 1
145 #warn $@;
146 } else {
147 1 push @roots, $FindBin::Bin;
148 }
149  
150 1 ▶ Jifty::Util->require('ExtUtils::MM') if $^O =~ /(?:MSWin32|cygwin|os2)/;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /(?:MSWin32|cygwin|os2)/ 0 1 1
151 1 Jifty::Util->require('Config');
152 1 for my $root_path (@roots) {
153 1 my ($volume, $dirs) = File::Spec->splitpath($root_path, 'no_file');
154 1 my @root = File::Spec->splitdir($dirs);
155 1 ▶ while (@root) {
Branch: 1 branch
BranchTrueFalseTotal
if (@root) 1 0 1
156 1 my $try = File::Spec->catpath($volume, File::Spec->catdir( @root, "bin", "jifty" ), '');
157 1 ▶ if (# XXX: Just a quick hack
Branch: 1 branch
BranchTrueFalseTotal
if (-e $try || $^O =~ /(?:MSWin32|cygwin|os2)/ && "MM"->maybe_command($try) and lc $try ne lc "File::Spec"->catdir($Config::Config{"bin"}, "jifty") and lc $try ne lc "File::Spec"->catdir($Config::Config{"scriptdir"}, "jifty")) 1 0 1
Condition25%3/12
-e $try || $^O =~ /(?:MSWin32|cygwin|os2)/ && "MM"->maybe_command($try) and lc $try ne lc "File::Spec"->catdir($Config::Config{"bin"}, "jifty") and lc $try ne lc "File::Spec"->catdir($Config::Config{"scriptdir"}, "jifty")
!ll&&!rl&&r
001
-e $try || $^O =~ /(?:MSWin32|cygwin|os2)/ && "MM"->maybe_command($try) and lc $try ne lc "File::Spec"->catdir($Config::Config{"bin"}, "jifty")
!ll&&!rl&&r
001
-e $try or $^O =~ /(?:MSWin32|cygwin|os2)/ and "MM"->maybe_command($try)
l!l&&r!l&&!r
100
$^O =~ /(?:MSWin32|cygwin|os2)/ and "MM"->maybe_command($try)
!ll&&!rl&&r
000
MC/DC0%0/5
-e $try || $^O =~ /(?:MSWin32|cygwin|os2)/ && "MM"->maybe_command($try) and lc $try ne lc "File::Spec"->catdir($Config::Config{"bin"}, "jifty") and lc $try ne lc "File::Spec"->catdir($Config::Config{"scriptdir"}, "jifty")
-e $try $^O =~ /(?:MSWin32|cygwin|os2)/ "MM"->maybe_command($try) lc $try ne lc "File::Spec"->catdir($Config::Config{"bin"}, "jifty") lc $try ne lc "File::Spec"->catdir($Config::Config{"scriptdir"}, "jifty")
Truth table12%1/8
A or B and C and D and E
A= -e $tryB= $^O =~ /(?:MSWin32|cygwin|os2)/C= "MM"->maybe_command($try)D= lc $try ne lc "File::Spec"->catdir($Config::Config{"bin"}, "jifty")E= lc $try ne lc "File::Spec"->catdir($Config::Config{"scriptdir"}, "jifty")
ABCDEresult
00XXX0
010XX0
1XX0X0
0110X0
1XX100
011100
1XX111
011111
158 # MSWin32's 'maybe_command' sees only file extension.
159 # Maybe we should check 'jifty.bat' instead on Win32,
160 # if it is (or would be) provided.
161 # Also, /usr/bin or /usr/local/bin should be taken from
162 # %Config{bin} or %Config{scriptdir} or something like that
163 # for portablility.
164 # Note that to compare files in Win32 we have to ignore the case
165 (-e $try or (($^O =~ /(?:MSWin32|cygwin|os2)/) and MM->maybe_command($try)))
166 and lc($try) ne lc(File::Spec->catdir($Config::Config{bin}, "jifty"))
167 and lc($try) ne lc(File::Spec->catdir($Config::Config{scriptdir}, "jifty")) )
168 {
169 1 return $APP_ROOT = File::Spec->catpath($volume, File::Spec->catdir(@root), '');
170 }
171 0 pop @root;
172 }
173 }
174 warn "Can't guess application root from current path ("
175 . Cwd::cwd()
176 0 ▶ . ") or bin path ($FindBin::Bin)\n" unless $args{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"quiet"} 0 0 0
177 0 return ''; # returning undef causes tons of 'uninitialized...' warnings.
178 }
179  
180 =head2 is_app_root PATH
181  
182 Returns a boolean indicating whether the path passed in is the same path as
183 the app root. Useful if you're recursing up a directory tree and want to
184 stop when you've hit the root. It does not attempt to handle symbolic links.
185  
186 =cut
187  
188 sub is_app_root
189 0 ▶{
Subroutine is_app_root: not called CC=1 SCAR=6.9
Pod documented
190 0 my $self = shift;
191 0 my $path = shift;
192 0 my $app_root = $self->app_root;
193  
194 0 my $rel = File::Spec->abs2rel( $path, $app_root );
195  
196 0 return $rel eq File::Spec->curdir;
197 }
198  
199 =head2 default_app_name
200  
201 Returns the default name of the application. This is the name of the
202 application's root directory, as defined by L</app_root>.
203  
204 =cut
205  
206 0 ▶sub default_app_name {
Subroutine default_app_name: not called CC=3 SCAR=24.8
Pod documented
207 0 my $self = shift;
208 0 my @root = File::Spec->splitdir( Jifty::Util->app_root);
209 0 my $name = pop @root;
210  
211 # Jifty-0.10211 should become Jifty
212 0 ▶ $name = $1 if $name =~ /^(.*?)-(.*\..*)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /^(.*?)-(.*\..*)$/ 0 0 0
213  
214 # But don't actually allow "Jifty" as the name
215 0 ▶ $name = "JiftyApp" if lc $name eq "jifty";
Branch: 1 branch
BranchTrueFalseTotal
if lc $name eq "jifty" 0 0 0
216  
217 0 return $name;
218 }
219  
220 =head2 make_path PATH
221  
222 When handed a directory, creates that directory, starting as far up the
223 chain as necessary. (This is what 'mkdir -p' does in your shell).
224  
225 =cut
226  
227 0 ▶sub make_path {
Subroutine make_path: not called CC=3 SCAR=24.8
Pod documented
228 0 my $self = shift;
229 0 my $whole_path = shift;
230 0 ▶ return 1 if (-d $whole_path);
Branch: 1 branch
BranchTrueFalseTotal
if -d $whole_path 0 0 0
231 0 Jifty::Util->require('File::Path');
232  
233 0 local $@;
234 0 eval { File::Path::mkpath([$whole_path]) };
235  
236 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
237 0 Jifty->log->fatal("Unable to make path: $whole_path: $@")
238 }
239 }
240  
241 =head2 require PATH
242  
243 Uses L<UNIVERSAL::require> to require the provided C<PATH>.
244 Additionally, logs any failures at the C<error> log level.
245  
246 =cut
247  
248 2 ▶sub require {
Subroutine require: called CC=1 SCAR=0.0
Pod documented
249 2 my $self = shift;
250 2 my $module = shift;
251 2 $self->_require( module => $module, quiet => 0);
252 }
253  
254 2 ▶sub _require {
Subroutine _require: called CC=11 SCAR=33.8
255 2 my $self = shift;
256 2 my %args = ( module => undef, quiet => undef, @_);
257 2 my $class = $args{'module'};
258  
259 # Quick hack to silence warnings.
260 # Maybe some dependencies were lost.
261 2 ▶ unless ($class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 2 2
262 0 Jifty->log->error(sprintf("no class was given at %s line %d\n", (caller)[1,2]));
263 0 return 0;
264 }
265  
266 2 ▶ return 1 if $self->already_required($class);
Branch: 1 branch
BranchTrueFalseTotal
if $self->already_required($class) 1 1 2
267  
268 # .pm might already be there in a weird interaction in Module::Pluggable
269 1 my $file = $class;
270 1 ▶ $file .= ".pm"
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\.pm$/ 1 0 1
271 unless $file =~ /\.pm$/;
272  
273 1 $file =~ s/::/\//g;
274  
275 1 my $retval = eval {CORE::require "$file"} ;
276 1 my $error = $@;
277 1 ▶ if (my $message = $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $message = $error) 0 1 1
278 0 $message =~ s/ at .*?\n$//;
279 0 ▶ if ($args{'quiet'} and $message =~ /^Can't locate $file/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'quiet'} and $message =~ /^Can't locate $file/) { } 0 0 0
elsif (not $error =~ /^Can't locate $file/) { } 0 0 0
Condition0%0/3
$args{"quiet"} and $message =~ /^Can't locate $file/
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"quiet"} and $message =~ /^Can't locate $file/
$args{"quiet"} $message =~ /^Can't locate $file/
Truth table0%0/3
A and B
A= $args{"quiet"}B= $message =~ /^Can't locate $file/
ABresult
0X0
100
111
280 0 return 0;
281 }
282 elsif ( $error !~ /^Can't locate $file/) {
283 0 die $error;
284 } else {
285 0 Jifty->log->error(sprintf("$message at %s line %d\n", (caller(1))[1,2]));
286 0 return 0;
287 }
288 }
289  
290 # If people forget the '1;' line in the dispatcher, don't eit them
291 1 ▶ if ($class =~ /::Dispatcher$/ and ref $retval eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /::Dispatcher$/ and ref $retval eq "ARRAY") 0 1 1
Condition33%1/3
$class =~ /::Dispatcher$/ and ref $retval eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
$class =~ /::Dispatcher$/ and ref $retval eq "ARRAY"
$class =~ /::Dispatcher$/ ref $retval eq "ARRAY"
Truth table33%1/3
A and B
A= $class =~ /::Dispatcher$/B= ref $retval eq "ARRAY"
ABresult
0X0
100
111
292 0 Jifty->log->error("$class did not return a true value; assuming it was a dispatcher rule");
293 0 Jifty::Dispatcher::_push_rule($class, $_) for @{$retval};
294 }
295  
296 1 return 1;
297 }
298  
299 =head2 try_to_require Module
300  
301 This method works just like L</require>, except that it suppresses the error message
302 in cases where the module isn't found.
303  
304 =cut
305  
306 0 ▶sub try_to_require {
Subroutine try_to_require: not called CC=1 SCAR=6.9
Pod documented
307 0 my $self = shift;
308 0 my $module = shift;
309 0 $self->_require( module => $module, quiet => 1);
310 }
311  
312  
313 =head2 already_required class
314  
315 Helper function to test whether a given class has already been loaded.
316  
317 =cut
318  
319 2 ▶sub already_required {
Subroutine already_required: called CC=2 SCAR=6.9
Pod documented
320 2 my ($self, $class) = @_;
321 2 $class =~ s{::}{/}g;
322 2 ▶ return ( $INC{"$class.pm"} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$INC{"$class.pm"} ? : 1 1 2
323 }
324  
325 =head2 generate_uuid
326  
327 Generate a new UUID using B<Data::UUID>.
328  
329 =cut
330  
331 6 my $Data_UUID_instance;
332 0 ▶sub generate_uuid {
Subroutine generate_uuid: not called CC=2 SCAR=17.9
Pod documented
333 0 ▶ ($Data_UUID_instance ||= do {
Condition0%0/3
$Data_UUID_instance ||= do { require Data::UUID; "Data::UUID"->new }
l!l&&r!l&&!r
000
MC/DC0%0/2
$Data_UUID_instance ||= do { require Data::UUID; "Data::UUID"->new }
$Data_UUID_instance do { require Data::UUID; "Data::UUID"->new }
Truth table0%0/3
A ||= B
A= $Data_UUID_instanceB= do { require Data::UUID; "Data::UUID"->new }
ABresult
1X1
011
000
334 0 require Data::UUID;
335 0 Data::UUID->new;
336 })->create_str;
337 }
338  
339 =head2 reference_to_data Object
340  
341 Provides a saner output format for models than
342 C<MyApp::Model::Foo=HASH(0x1800568)>.
343  
344 =cut
345  
346 0 ▶sub reference_to_data {
Subroutine reference_to_data: not called CC=3 SCAR=24.8
Pod documented
347 0 my ($self, $obj) = @_;
348 0 (my $model = ref($obj)) =~ s/::/./g;
349 0 my $id = $obj->id;
350  
351 # probably a file extension, from the REST rewrite
352 0 my $extension = '';
353 0 ▶ if (Jifty->web->request &&
Branch: 1 branch
BranchTrueFalseTotal
if ("Jifty"->web->request and "Jifty"->web->request->env->{"HTTP_ACCEPT"} =~ /^\w+$/) 0 0 0
Condition0%0/3
"Jifty"->web->request and "Jifty"->web->request->env->{"HTTP_ACCEPT"} =~ /^\w+$/
!ll&&!rl&&r
000
MC/DC0%0/2
"Jifty"->web->request and "Jifty"->web->request->env->{"HTTP_ACCEPT"} =~ /^\w+$/
"Jifty"->web->request "Jifty"->web->request->env->{"HTTP_ACCEPT"} =~ /^\w+$/
Truth table0%0/3
A and B
A= "Jifty"->web->requestB= "Jifty"->web->request->env->{"HTTP_ACCEPT"} =~ /^\w+$/
ABresult
0X0
100
111
354 Jifty->web->request->env->{HTTP_ACCEPT} =~ m/^\w+$/) {
355 0 $extension = '.'.Jifty->web->request->env->{HTTP_ACCEPT};
356 }
357  
358 return {
359 0 jifty_model_reference => 1,
360 id => $obj->id,
361 model => $model,
362 url => Jifty->web->url(path => "/=/model/$model/id/$id$extension"),
363 };
364 }
365  
366 =head2 stringify LIST
367  
368 Takes a list of values and forces them into strings. Right now all it does
369 is concatenate them to an empty string, but future versions might be more
370 magical.
371  
372 =cut
373  
374 0 ▶sub stringify {
Subroutine stringify: not called CC=7 SCAR=40.3
Pod documented
375 0 my $self = shift;
376  
377 0 my @r;
378  
379 0 for (@_) {
380 0 ▶ if (UNIVERSAL::isa($_, 'Jifty::Record')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_, "Jifty::Record")) 0 0 0
381 0 push @r, Jifty::Util->reference_to_data($_);
382 }
383 0 ▶ if (UNIVERSAL::isa($_, 'Jifty::DateTime') && $_->is_date) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($_, 'Jifty::DateTime') and $_->is_date) { } 0 0 0
elsif (defined $_) { } 0 0 0
Condition0%0/3
UNIVERSAL::isa($_, "Jifty::DateTime") and $_->is_date
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::isa($_, "Jifty::DateTime") and $_->is_date
UNIVERSAL::isa($_, "Jifty::DateTime") $_->is_date
Truth table0%0/3
A and B
A= UNIVERSAL::isa($_, "Jifty::DateTime")B= $_->is_date
ABresult
0X0
100
111
384 0 push @r, $_->ymd;
385 }
386 elsif (defined $_) {
387 0 push @r, '' . $_; # force stringification
388 }
389 else {
390 0 push @r, undef;
391 }
392 }
393  
394 0 ▶ return wantarray ? @r : $r[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
395 }
396  
397 =head1 AUTHOR
398  
399 Various folks at Best Practical Solutions, LLC.
400  
401 =cut
402  
403 6 1;
« Jifty/Plugin/REST/Dispatcher.pm ↑ Summary Jifty/Web/Form/Field/OrderedList.pm »