1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
4 // See accompanying file LICENSE or visit the Thrift site at:
5 // http://developers.facebook.com/thrift/
7 #ifndef T_PERL_GENERATOR_H
8 #define T_PERL_GENERATOR_H
15 #include "t_oop_generator.h"
18 * PERL code generator.
20 * @author Jake Luciani <jakers@gmail.com>
22 class t_perl_generator
: public t_oop_generator
{
24 t_perl_generator(t_program
* program
) :
25 t_oop_generator(program
) {
27 out_dir_base_
= "gen-perl";
31 * Init and close methods
34 void init_generator();
35 void close_generator();
38 * Program-level generation functions
41 void generate_typedef (t_typedef
* ttypedef
);
42 void generate_enum (t_enum
* tenum
);
43 void generate_const (t_const
* tconst
);
44 void generate_struct (t_struct
* tstruct
);
45 void generate_xception (t_struct
* txception
);
46 void generate_service (t_service
* tservice
);
48 std::string
render_const_value(t_type
* type
, t_const_value
* value
);
54 void generate_perl_struct(t_struct
* tstruct
, bool is_exception
);
55 void generate_perl_struct_definition(std::ofstream
& out
, t_struct
* tstruct
, bool is_xception
=false);
56 void generate_perl_struct_reader(std::ofstream
& out
, t_struct
* tstruct
);
57 void generate_perl_struct_writer(std::ofstream
& out
, t_struct
* tstruct
);
58 void generate_perl_function_helpers(t_function
* tfunction
);
61 * Service-level generation functions
64 void generate_service_helpers (t_service
* tservice
);
65 void generate_service_interface (t_service
* tservice
);
66 void generate_service_rest (t_service
* tservice
);
67 void generate_service_client (t_service
* tservice
);
68 void generate_service_processor (t_service
* tservice
);
69 void generate_process_function (t_service
* tservice
, t_function
* tfunction
);
72 * Serialization constructs
75 void generate_deserialize_field (std::ofstream
&out
,
77 std::string prefix
="",
80 void generate_deserialize_struct (std::ofstream
&out
,
82 std::string prefix
="");
84 void generate_deserialize_container (std::ofstream
&out
,
86 std::string prefix
="");
88 void generate_deserialize_set_element (std::ofstream
&out
,
90 std::string prefix
="");
92 void generate_deserialize_map_element (std::ofstream
&out
,
94 std::string prefix
="");
96 void generate_deserialize_list_element (std::ofstream
&out
,
98 std::string prefix
="");
100 void generate_serialize_field (std::ofstream
&out
,
102 std::string prefix
="");
104 void generate_serialize_struct (std::ofstream
&out
,
106 std::string prefix
="");
108 void generate_serialize_container (std::ofstream
&out
,
110 std::string prefix
="");
112 void generate_serialize_map_element (std::ofstream
&out
,
117 void generate_serialize_set_element (std::ofstream
&out
,
121 void generate_serialize_list_element (std::ofstream
&out
,
126 * Helper rendering functions
129 std::string
perl_includes();
130 std::string
declare_field(t_field
* tfield
, bool init
=false, bool obj
=false);
131 std::string
function_signature(t_function
* tfunction
, std::string prefix
="");
132 std::string
argument_list(t_struct
* tstruct
);
133 std::string
type_to_enum(t_type
* ttype
);
135 std::string
autogen_comment() {
138 "# Autogenerated by Thrift\n" +
140 "# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" +
144 std::string
perl_namespace(t_program
* p
) {
145 std::string ns
= p
->get_perl_package();
146 return ns
.empty() ? ns
: (ns
+ "::");
154 std::ofstream f_types_
;
155 std::ofstream f_consts_
;
156 std::ofstream f_helpers_
;
157 std::ofstream f_service_
;