使用元编程在 Perl 中实现 SOAP 客户端是否明智?
我当前正在处理一个代码库,其中包含用 SOAP::WSDL 生成的几十个类。然而,在使用 Moose 后,我现在认为在运行时在元级别生成这些类(即不是磁盘上的文件而是直接生成对象)可能是一个更好的主意(此时完全排除性能原因)。
这种方法明智吗?这个想法是为了避免更改生成的代码,并避免偶尔重新生成它。
如果是,是否有任何从 WSDL 创建类的现成 Perl 模块?
I'm currently dealing with a code base which contains several dozens of classes generated with SOAP::WSDL. However, having worked with Moose I now think that generating those classes at runtime at meta level (i.e. not to files on disk but directly to objects) might be a better idea (completely excluding performance reasons at this point).
Is this approach sensible? The idea is to avoid changes to generated code and also to avoid re-generating it once in a while.
If so, are there any ready-to-use Perl modules that create classes from a WSDL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先回答第二个问题,没有任何基于 Moose 的东西可以将 WSDL 转换为一组类。然而,您可以基于 XML::Toolkit 构建一些东西。为了充分披露,XML::Toolkit 是我的模块,它具有用于将 SAX 流转换为 Moose 类的工具,反之亦然。对于非 Moose Perl 类,有 XML::Compile 我相信它可以编译 SOAP wsdl ->珀尔。
为了回答第一个问题,我使用 XML::Toolkit 的经验表明,在运行时将类保留在内存中是很棘手的。忽略性能开销,您需要记住许多从 WSDL 中夸大的内容。这将是一个有趣的实验,但我不确定它的可维护性有多长。
我很长一段时间以来都想尝试这样的事情,但我还没有一个项目能让我真正专注于不幸的是我也没有空闲时间来处理这么大的项目。
To answer the second question first, there is nothing Moose based that will turn a WSDL into a set of classes. However you could possibly build something based on XML::Toolkit. For full disclosure XML::Toolkit is my module that has tools for converting SAX streams into Moose classes and vice versa. For non-Moose Perl classes, there is XML::Compile which I believe can compile SOAP wsdl -> Perl.
To answer the first question, my experience with XML::Toolkit says that keeping the classes in memory at run-time is tricky. Ignoring the performance overhead there is a lot of stuff you'll need to keep in your head that are inflated from the WSDL. It would be an interesting experiment, but I"m not sure how long-term maintainable it would be.
I've wanted for a long time to try something like this but I haven't had a project that paid me to really focus on it. Unfortunately I don't have the free time to tackle a project of this size either.