line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hyper::Developer::Generator::Control; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2049
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
5
|
use version; our $VERSION = qv('0.01'); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
13
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
80
|
use base qw(Hyper::Developer::Generator); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
159
|
|
8
|
|
|
|
|
|
|
use Class::Std; |
9
|
|
|
|
|
|
|
use Hyper::Functions; |
10
|
|
|
|
|
|
|
use File::Path (); |
11
|
|
|
|
|
|
|
use Hyper::Error; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %usecase_of :ATTR(:name); |
14
|
|
|
|
|
|
|
my %service_of :ATTR(:name); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# spec for gen. target |
17
|
|
|
|
|
|
|
my %type_of :ATTR(:set); |
18
|
|
|
|
|
|
|
my %sub_path_of :ATTR(:set); |
19
|
|
|
|
|
|
|
my %suffix_of :ATTR(:set); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub create { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
my $arg_ref = shift || {}; # name, template, force, data |
24
|
|
|
|
|
|
|
my $ident = ident $self; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# $arg_ref->{name} => mandatory |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $path = $self->get_base_path() |
29
|
|
|
|
|
|
|
. '/' . Hyper::Functions::get_path_for($type_of{$ident}) |
30
|
|
|
|
|
|
|
. '/' . $self->get_namespace() |
31
|
|
|
|
|
|
|
. '/' . $sub_path_of{$ident} |
32
|
|
|
|
|
|
|
. '/' . $self->get_service(); |
33
|
|
|
|
|
|
|
my $file = "$path/$arg_ref->{name}.$suffix_of{$ident}"; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# TODO modify to use IO::File->new( $file, O_CREAT | O_WRONLY | O_EXCL) |
36
|
|
|
|
|
|
|
# instead of "warn if -e $file"; |
37
|
|
|
|
|
|
|
# open my $fh, $file if ( not (-e $file) ) |
38
|
|
|
|
|
|
|
# is a race condition: If someone manages to put a file in place |
39
|
|
|
|
|
|
|
# between -e and open, we clobber an existing file... |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# return if file exists and force isn't set |
42
|
|
|
|
|
|
|
my $force = exists $arg_ref->{force} |
43
|
|
|
|
|
|
|
? $arg_ref->{force} |
44
|
|
|
|
|
|
|
: $self->get_force(); |
45
|
|
|
|
|
|
|
if ( ! $force && -e $file ) { |
46
|
|
|
|
|
|
|
warn "can't generate code, destination file >$file< exists"; |
47
|
|
|
|
|
|
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
File::Path::mkpath([$path], 0, 0770); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $template = $self->get_template(); |
53
|
|
|
|
|
|
|
$template->process( |
54
|
|
|
|
|
|
|
$arg_ref->{template}, |
55
|
|
|
|
|
|
|
{ data => $arg_ref->{data}, |
56
|
|
|
|
|
|
|
this => $self, |
57
|
|
|
|
|
|
|
name => $arg_ref->{name}, |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
$file, |
60
|
|
|
|
|
|
|
) or throw($template->error()); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return $self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |