blib/lib/CatalystX/Controller/ExtJS/ImageChooser.pm

filter: Statementstmt 47.3% 18 / 38 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 66.6% 6 / 9 Podpod n/a totaltotal 33.8% 24 / 71 CC 9 SCAR 32.4
CC
9
Cov
32%
foo
56.0
new
12.0
_parse_NSPathPart_attr
2.0
CRAP 25.6
↑ Summary tutorial/lib/MyApp/Controller/User/DBIC.pm »
1 #
2 # This file is part of CatalystX-ExtJS
3 #
4 # This software is Copyright (c) 2011 by Moritz Onken.
5 #
6 # This is free software, licensed under:
7 #
8 # The (three-clause) BSD License
9 #
10 package CatalystX::Controller::ExtJS::ImageChooser;
11 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 $CatalystX::Controller::ExtJS::ImageChooser::VERSION = '2.1.3';
13 }
14 # ABSTRACT: Controller for the ExtJS ImageChooser class
15  
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use base 'Catalyst::Controller', 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 __PACKAGE__->mk_accessors('_extjs_ic_config');
23  
24 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
25 0 my $self = shift->next::method(@_);
26 0 my ($c) = @_;
27  
28 0 ▶ my $self_config = $self->config || {};
Condition0%0/2
$self->config || {}
l!l
00
MC/DC0%0/1
$self->config || {}
$self->config
Truth table0%0/2
A
A= $self->config
Aresult
11
00
29 0 ▶ my $parent_config = $c->config->{'Controller::ExtJS:ImageChooser'} || {};
Condition0%0/2
$c->config->{'Controller::ExtJS:ImageChooser'} || {}
l!l
00
MC/DC0%0/1
$c->config->{'Controller::ExtJS:ImageChooser'} || {}
$c->config->{'Controller::ExtJS:ImageChooser'}
Truth table0%0/2
A
A= $c->config->{'Controller::ExtJS:ImageChooser'}
Aresult
11
00
30  
31 0 $self->_extjs_ic_config( { %$self_config, %$parent_config } );
32  
33 0 return $self;
34  
35 }
36  
37 0 ▶sub _parse_NSPathPart_attr {
Subroutine _parse_NSPathPart_attr: not called CC=1 SCAR=6.9
38 0 my ( $self, $c ) = @_;
39 0 return ( PathPart => $self->action_namespace );
40 }
41  
42 0 ▶sub foo : Chained('/') NSPathPart Args {
Subroutine foo: not called CC=7 SCAR=40.3
43 0 my ( $self, $c ) = @_;
44 0 my $config = $self->_extjs_ic_config;
45 croak
46 q(please specify __PACKAGE__->config({image_chooser_dir => '...', image_chooser_url => '...'}))
47 0 ▶ unless ( $config->{image_chooser_dir} && $config->{image_chooser_url} );
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"image_chooser_dir"} and $config->{"image_chooser_url"} 0 0 0
Condition0%0/3
$config->{"image_chooser_dir"} and $config->{"image_chooser_url"}
!ll&&!rl&&r
000
MC/DC0%0/2
$config->{"image_chooser_dir"} and $config->{"image_chooser_url"}
$config->{"image_chooser_dir"} $config->{"image_chooser_url"}
Truth table0%0/3
A and B
A= $config->{"image_chooser_dir"}B= $config->{"image_chooser_url"}
ABresult
0X0
100
111
48  
49 0 my @images = ();
50  
51 0 my $base = Path::Class::Dir->new( $config->{image_chooser_dir} );
52 0 my $dir = $base->subdir(@{$c->req->args});
53
54 0 ▶ croak "$dir is a parent of $base" if($dir ne $base && $dir->subsumes($base));
Branch: 1 branch
BranchTrueFalseTotal
if $dir ne $base and $dir->subsumes($base) 0 0 0
Condition0%0/3
$dir ne $base and $dir->subsumes($base)
!ll&&!rl&&r
000
MC/DC0%0/2
$dir ne $base and $dir->subsumes($base)
$dir ne $base $dir->subsumes($base)
Truth table0%0/3
A and B
A= $dir ne $baseB= $dir->subsumes($base)
ABresult
0X0
100
111
55
56 0 ▶ while ( my $file = $dir->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $dir->next) 0 0 0
57 0 ▶ next if $file->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $file->is_dir 0 0 0
58 push(
59 @images,
60 {
61 name => $file->basename,
62 size => $file->stat->size,
63 lastmod => $file->stat->mtime,
64 0 url => $config->{image_chooser_url} . "/" . $file->basename
65 }
66 );
67  
68 }
69 0 $c->stash({images => \@images});
70  
71 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 1 1;
74  
75  
76  
77 =pod
78  
79 =head1 NAME
80  
81 CatalystX::Controller::ExtJS::ImageChooser - Controller for the ExtJS ImageChooser class
82  
83 =head1 VERSION
84  
85 version 2.1.3
86  
87 =head1 SYNOPSIS
88  
89 package MyApp::Controller::Images;
90
91 use base 'CatalystX::Controller::ExtJS::Image::Chooser';
92
93 __PACKAGE__->config(
94 {
95 image_chooser_dir => 'root/static/images',
96 image_chooser_url => '/static/images'
97 }
98 );
99
100 # use a JSON view
101
102 # output is available at /images
103
104 1;
105  
106 Example at L<http://www.extjs.com/deploy/dev/examples/view/chooser.html>.
107  
108 =head1 DESCRIPTION
109  
110 This module generates an object which can be serialized to a json string. The ImageChooser class of ExtJS expects
111 the data in this way.
112  
113 You can even look in subdirectories by simply adding the directory name to the url. Example: C</images/subdir> gives you the
114 files from C<root/static/images/subdir>. You cannot access directories, which are parents of the base directory.
115  
116 =head1 AUTHOR
117  
118 Moritz Onken <onken@netcubed.de>
119  
120 =head1 COPYRIGHT AND LICENSE
121  
122 This software is Copyright (c) 2011 by Moritz Onken.
123  
124 This is free software, licensed under:
125  
126 The (three-clause) BSD License
127  
128 =cut
129  
130  
131 __END__
↑ Summary tutorial/lib/MyApp/Controller/User/DBIC.pm »