« blib/lib/YATT/Lite/Test/LangServerClient.pm
↑ Summary
blib/lib/YATT/Lite/WebMVC0/DBSchema/DBIC.pm »
| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Cwd (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use List::MoreUtils qw/last_index/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | my ($app_root, @libdir); | |||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # First, locate YATT library dir. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=10 SCAR=37.6
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | if (-r __FILE__) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | # detect where app.psgi is placed. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | $app_root = File::Basename::dirname(File::Spec->rel2abs(__FILE__)); | |||||||||||||||||||||||||||||||||||||||||
| 20 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # older uwsgi do not set __FILE__ correctly, so use cwd instead. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $app_root = Cwd::cwd(); | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | $app_root = do { $app_root =~ m{^(.*)$} && $& }; # Untaint. | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$app_root =~ /^(.*)$/ && $&
MC/DC0%0/2
$app_root =~ /^(.*)$/ && $&
$app_root =~ /^(.*)$/
$&
Truth table33%1/3
A && B
A= $app_root =~ /^(.*)$/B= $&
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | if (-d (my $dn = "$app_root/lib")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | push @libdir, $dn | |||||||||||||||||||||||||||||||||||||||||
| 27 | } elsif (my ($found) = $app_root =~ m{^(.*?/)YATT/samples(?:/|\z)}) { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | push @libdir, $found; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | if (-d (my $dn = "$app_root/extlib")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | push @libdir, $dn; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | require lib; import lib @libdir; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | if (not eval {require YATT::Lite::Breakpoint} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not eval {
do {
require YATT::Lite::Breakpoint
}
} and -l __FILE__ and (my $d = &last_index(sub {
$_ eq "samples";
}
, my(@d) = "File::Spec"->splitdir(__FILE__))) >= 0
not eval {
do {
require YATT::Lite::Breakpoint
}
} and -l __FILE__
MC/DC0%0/3
not eval {
do {
require YATT::Lite::Breakpoint
}
} and -l __FILE__ and (my $d = &last_index(sub {
$_ eq "samples";
}
, my(@d) = "File::Spec"->splitdir(__FILE__))) >= 0
not eval {
do {
require YATT::Lite::Breakpoint
}
}
-l __FILE__
(my $d = &last_index(sub {
$_ eq "samples";
}
, my(@d) = "File::Spec"->splitdir(__FILE__))) >= 0
Truth table25%1/4
not(A) and B and C
A= not eval {
do {
require YATT::Lite::Breakpoint
}
}B= -l __FILE__C= (my $d = &last_index(sub {
$_ eq "samples";
}
, my(@d) = "File::Spec"->splitdir(__FILE__))) >= 0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | and -l __FILE__ | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | and (my $d = last_index {$_ eq 'samples'} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | my @d = File::Spec->splitdir(__FILE__)) >= 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | print STDERR "d=$d; @d\n" if $ENV{DEBUG_INC}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $dir = File::Spec->catdir(@d[0 .. ($d - 1)]); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $hook = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my ($this, $orig_modfn) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return unless (my $modfn = $orig_modfn) =~ s!^YATT/!!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | Carp::cluck("orig_modfn=$orig_modfn\n") if $ENV{DEBUG_INC}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return unless -r (my $realfn = "$dir/../$modfn"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | warn "=> found $realfn" if $ENV{DEBUG_INC}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | open my $fh, '<', $realfn or die "Can't open $realfn:$!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $fh; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | unshift @INC, $hook; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | push @INC, $hook, $hook; | |||||||||||||||||||||||||||||||||||||||||
| 54 | # XXX: @INC-hook Only Live Twice :-< | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # Now, we are ready to load YATT libraries. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | use YATT::Lite::WebMVC0::SiteApp -as_base; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | use YATT::Lite qw/Entity *CON/; # For Entity and $CON. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # To add other option, use MFields like this: | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # use YATT::Lite::MFields qw/dbi_dsn auto_deploy /; | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | my $site = MY->load_factory_for_psgi | ||||||||||||||||||||||||||||||||||||||||||
| 70 | (__FILE__, app_ns => 'MyYATT' | ||||||||||||||||||||||||||||||||||||||||||
| 71 | , namespace => ['yatt', 'perl', 'js'] | ||||||||||||||||||||||||||||||||||||||||||
| 72 | , header_charset => 'utf-8' | ||||||||||||||||||||||||||||||||||||||||||
| 73 | , use_subpath => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 74 | , debug_cgen => $ENV{DEBUG_CGEN} | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ; | |||||||||||||||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # Site wide entity can be defined here. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # Entity foo => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # my ($this, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # }; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | my $app = $site->to_app; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | unless (caller) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | # If this script is the toplevel. | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | require Plack::Runner; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $runner = Plack::Runner->new(app => $app); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $runner->parse_options(@ARGV); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $runner->run; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | } elsif ($site->want_object) { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # When caller wants $site object itself rather than app sub. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # (Usually for yatt.lint and other utils) | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | return $site; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # Otherwise, returns psgi app. | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return $app; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||