| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dancer::Engine; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:SUKRIA'; |
|
3
|
|
|
|
|
|
|
#ABSTRACT: base class for Dancer engines |
|
4
|
|
|
|
|
|
|
$Dancer::Engine::VERSION = '1.3521'; |
|
5
|
|
|
|
|
|
|
# This is the base-class of every engine abstract class. |
|
6
|
|
|
|
|
|
|
# This allow us to put in that single place the engine creation |
|
7
|
|
|
|
|
|
|
# from a namespace and a name, to its configuration initialization. |
|
8
|
|
|
|
|
|
|
|
|
9
|
195
|
|
|
195
|
|
1999
|
use strict; |
|
|
195
|
|
|
|
|
423
|
|
|
|
195
|
|
|
|
|
5866
|
|
|
10
|
195
|
|
|
195
|
|
1103
|
use warnings; |
|
|
195
|
|
|
|
|
444
|
|
|
|
195
|
|
|
|
|
4947
|
|
|
11
|
195
|
|
|
195
|
|
1001
|
use Carp; |
|
|
195
|
|
|
|
|
424
|
|
|
|
195
|
|
|
|
|
10145
|
|
|
12
|
195
|
|
|
195
|
|
4770
|
use Dancer::ModuleLoader; |
|
|
195
|
|
|
|
|
402
|
|
|
|
195
|
|
|
|
|
4923
|
|
|
13
|
195
|
|
|
195
|
|
1069
|
use base 'Dancer::Object'; |
|
|
195
|
|
|
|
|
471
|
|
|
|
195
|
|
|
|
|
26357
|
|
|
14
|
195
|
|
|
195
|
|
1418
|
use Dancer::Exception qw(:all); |
|
|
195
|
|
|
|
|
512
|
|
|
|
195
|
|
|
|
|
108287
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# constructor arguments: |
|
17
|
|
|
|
|
|
|
# name => $name_of_the_engine |
|
18
|
|
|
|
|
|
|
# settings => $hash_of_engine_settings |
|
19
|
|
|
|
|
|
|
Dancer::Engine->attributes(qw(name type)); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Accessor to the config hash, it may not be initialized if someone |
|
22
|
|
|
|
|
|
|
# creates a new engine without giving the appropriate arguments. |
|
23
|
|
|
|
|
|
|
# e.g. Dancer::Template::Simple->new(); |
|
24
|
|
|
|
|
|
|
sub config { |
|
25
|
449
|
|
|
449
|
1
|
1091
|
my ($self) = @_; |
|
26
|
449
|
100
|
|
|
|
3006
|
return $self->{config} if defined $self->{config}; |
|
27
|
57
|
|
|
|
|
280
|
$self->{config} = {}; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# static method for initializing an engine |
|
31
|
|
|
|
|
|
|
# this will create an engine instance of the appropriate $type, named $name |
|
32
|
|
|
|
|
|
|
# if Dancer::$type::$name exists. |
|
33
|
|
|
|
|
|
|
sub build { |
|
34
|
439
|
|
|
439
|
1
|
2573
|
my ($class, $type, $name, $config) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
439
|
100
|
66
|
|
|
2648
|
raise core_engine => "cannot build engine without type and name " |
|
37
|
|
|
|
|
|
|
unless $name and $type; |
|
38
|
|
|
|
|
|
|
|
|
39
|
438
|
|
|
|
|
1778
|
my $class_name = $class->_engine_class($type); |
|
40
|
|
|
|
|
|
|
|
|
41
|
438
|
|
100
|
|
|
1647
|
$config ||= {}; |
|
42
|
438
|
|
100
|
|
|
2440
|
$config->{engines} ||= {}; |
|
43
|
438
|
|
100
|
|
|
2363
|
my $settings = $config->{engines}{$name} || {}; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# trying to load the engine |
|
46
|
438
|
|
|
|
|
3029
|
my $engine_class = |
|
47
|
|
|
|
|
|
|
Dancer::ModuleLoader->class_from_setting($class_name => $name); |
|
48
|
|
|
|
|
|
|
|
|
49
|
438
|
|
|
|
|
2187
|
my( $loaded, $error ) = Dancer::ModuleLoader->load($engine_class); |
|
50
|
438
|
100
|
|
|
|
1781
|
$error = '' unless defined $error; |
|
51
|
|
|
|
|
|
|
|
|
52
|
438
|
100
|
|
|
|
1453
|
unless( $loaded ) { |
|
53
|
6
|
|
|
|
|
15
|
my $tip = ''; |
|
54
|
6
|
100
|
|
|
|
47
|
if( $error =~ /Can't locate (\S+)\.pm in \@INC/ ) { |
|
55
|
4
|
|
|
|
|
16
|
my $module = $1; |
|
56
|
4
|
|
|
|
|
25
|
$module =~ s#/#::#g; |
|
57
|
4
|
|
|
|
|
18
|
$tip = " (perhaps you need to install $module?)"; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
6
|
100
|
|
|
|
31
|
$error = ": $error" if length $error; |
|
61
|
6
|
|
|
|
|
48
|
raise core_engine => "unable to load $type engine '$name'$tip$error"; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# creating the engine |
|
65
|
432
|
|
|
|
|
4509
|
return $engine_class->new( |
|
66
|
|
|
|
|
|
|
name => $name, |
|
67
|
|
|
|
|
|
|
type => $type, |
|
68
|
|
|
|
|
|
|
config => $settings, |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _engine_class { |
|
73
|
488
|
|
|
488
|
|
1308
|
my ($class, $type) = @_; |
|
74
|
488
|
|
|
|
|
1894
|
$type = ucfirst($type); |
|
75
|
488
|
|
|
|
|
1771
|
return "Dancer::${type}"; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub engine { |
|
79
|
50
|
|
|
50
|
0
|
116
|
my ($class, $type) = @_; |
|
80
|
50
|
|
|
|
|
134
|
return $class->_engine_class($type)->engine(); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |