NAME
Protobuf::ClassGenerator - Generates Perl classes from Protocol Buffer descriptors
VERSION
version 0.04
SYNOPSIS
use Protobuf::ClassGenerator;
use Protobuf::DescriptorPool;
my $pool = Protobuf::DescriptorPool->generated_pool;
my $file_def = $pool->find_file_by_name('my/app/protos.proto');
# Generate classes for all messages in the file
Protobuf::ClassGenerator->generate_for_file($file_def);
# Now you can use the generated classes
# my $msg = My::App::Message->new();
DESCRIPTION
This module is responsible for dynamically creating Perl classes based on Protocol Buffer message descriptors (Protobuf::Descriptor::MessageDef). When a .proto file is loaded into a Protobuf::DescriptorPool, this generator is invoked to build the corresponding Moo-based Perl classes, complete with accessors and other methods for each field.
Key features of the generated classes:
Inherit from Protobuf::Message.
Have methods for getting, setting, checking presence, and clearing each field (e.g.,
my_field(),set_my_field(),has_my_field(),clear_my_field()).Return tied arrays/hashes for repeated/map fields, offering a standard Perl interface.
Associate the class with its Protobuf::Descriptor::MessageDef.
This module is primarily used internally by Protobuf::DescriptorPool when adding new file descriptors.
METHODS
generate_for_file($file_descriptor)
Takes a Protobuf::Descriptor::File object and generates Perl classes for all top-level and nested messages defined within that file. This method is called recursively for nested types.
generate_for_message($message_descriptor)
Generates the Perl class for a single Protobuf::Descriptor::MessageDef.
generate_type_library($file_descriptor)
(Experimental) Generates a string containing code for a Type::Library based on the message definitions in the given Protobuf::Descriptor::File.
type_library($file_descriptor)
Alias for generate_type_library.
generate_docs()
(Placeholder) Intended to generate HTML documentation from descriptors.
generate_validator_xs($message_descriptor)
(Experimental) Generates C code for a highly optimized validator function for the given message type.
SEE ALSO
Protobuf, Protobuf::DescriptorPool, Protobuf::Message, Protobuf::Descriptor
AUTHOR
C.J. Collier <cjac@google.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Google LLC.
This is free software; you can redistribute it and/or modify it under the terms of the BSD 3-Clause License.