=head1 NAME NACL::Events::Leaf - Base leaf event class for all NACL events =head1 DESCRIPTION C event class can be used for subscribing or publishing to NACL leaf events This library extends the functionality of C =cut package NACL::Events::Leaf; # inherit all methods from NATE::Events::Leaf use parent qw(NATE::Events::Leaf); =head2 publish_event Provide a simple way to publish leaf events in NACL For example to publish a volume create event $pkg_or_obj->publish_event(original_pkg_or_obj => $c_or_stask_pkg_or_obj, input_options => \%opts); =over =item Options =over =item C<< original_pkg_or_obj => $pkg_name >> (Mandatory) The original component or task package or object on which the method was invoked =item C<< input_options => $hashref>> (Mandatory) The hashref containing the options being passed to the method invoked on the original object =back =back =cut use NATE::Log qw(log_global); use Params::Validate qw(UNDEF validate_with :types ); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); sub publish { $Log->enter() if $may_enter; my ($event_obj, @args) = @_; my %args = validate_with( params => \@args, spec => { original_pkg_or_obj => {type => SCALAR | OBJECT}, input_options => {type => HASHREF}, } ); my (%ci_opts, %pks, @allowed_options, %msgs); my %opts = %{$args{input_options}}; my $pkg_or_obj = delete $args{original_pkg_or_obj}; my $command_interface = delete $opts{command_interface}; my $cli_cmd = delete $opts{cli_cmd}; $pkg_or_obj->_move_primary_keys(source => \%opts, target => \%pks); if ($cli_cmd && $command_interface->apiset( check_apiset_already_loaded => 1, interface => 'CLI' ) ) { my $cmd = $cli_cmd; $cmd =~ s/\s/_/g; $cmd =~ s/-/_/g; @allowed_options = $command_interface->apiset() ->get_allowed_options_for_command(command => $cmd); $pkg_or_obj->_hash_move( source => \%opts, move => \@allowed_options, target => \%msgs, ); } else { my @common_keys = ( keys %{$pkg_or_obj->_common_validate_spec()}, keys %{$pkg_or_obj->_additional_common_validate_spec()}, 'choices' ); $pkg_or_obj->_hash_move( source => \%opts, move => \@common_keys ); my %copy_opts = %opts; map { if ($_ =~ /^_/) { delete $opts{$_}; } } keys %copy_opts; %msgs = %opts; } $ci_opts{type} = ref $command_interface; $ci_opts{name} = $command_interface->name(); $msgs{command_interface_attributes} = \%ci_opts if (keys %ci_opts); $msgs{primary_keys} = \%pks if (keys %pks); $msgs{package_name} = $pkg_or_obj->get_package_name(); $event_obj->SUPER::publish(message => {message => \%msgs}); $Log->exit() if $may_exit; } ## end sub publish_event 1;