The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Log::Shiras::LogSpace - Log::Shiras Role for runtime name-spaces

SYNOPSIS

        use Modern::Perl;
        use MooseX::ShortCut::BuildInstance qw( build_class );
        use     lib
                        '../lib',;
        use Log::Shiras::LogSpace;
        my $test_instance = build_class(
                        package => 'Generic',
                        roles =>[ 'Log::Shiras::LogSpace' ],
                        add_methods =>{
                                get_class_space => sub{ 'ExchangeStudent' },
                                i_am => sub{
                                        my( $self )= @_;
                                        print "I am a: " . $self->get_all_space . "\n";
                                }
                        },
                );
        my $Generic = $test_instance->new;
        my $French = $test_instance->new( log_space => 'French' );
        my $Spanish = $test_instance->new( log_space => 'Spanish' );
        $Generic->i_am;
        $French->i_am;
        $Spanish->i_am;

        #######################################################################################
        # Synopsis Screen Output
        # 01: I am a: Generic::ExchangeStudent
        # 02: I am a: French::ExchangeStudent
        # 03: I am a: Spanish::ExchangeStudent
        #######################################################################################

DESCRIPTION

This attribute is useful to manage runtime Log::Shiras caller namespace. In the case where MyCoolPackage with Log::Shiras lines is used in more than one context then it is possible to pass a context sensitive name to the attribute log_space on intantiation of the instance and have the namespace bounds only activate the desired context of the package rather than have it report everywhere it is used. The telephone call in this case would look something like this;

        package MyCoolPackage

        sub get_class_space{ 'MyCoolPackage' }

        sub my_cool_sub{
                my( $self, $message ) = @_;
                my $phone = Log::Shiras::Telephone->new(
                                                name_space => $self->get_all_space . '::my_cool_sub',
                                        );
                $phone->talk( level => 'debug',
                        message => "Arrived at my_cool_sub with the message: $message" );
                # Do something cool here!
        }

In this case if you used my cool package instances with the log_space set to different values then only the namespace unblocked for 'FirstInstance::MyCoolPackage::my_cool_sub' would report. In the case where no sub 'get_class_space' is available the call to get_all_space will return the same value as 'get_log_space'.

Attributes

Data passed to new when creating an instance of the consuming class. For modification of this attribute see the listed attribute methods.

log_space

    Definition: This will be the base log_space element returned by get_all_space

    Default the consuming package name

    Range Any string, but Log::Shiras will look for '::' separators

    attribute methods

      get_log_space

        Definition: Returns the attribute value

      set_log_space( $string )

        Definition: sets the attribute value

      has_log_space

        Definition: predicate test for the attribute

Method

get_all_space

    Definition: This method collects the stored 'log_space' attribute value and then joins it with the results of a method call to 'get_class_space'. The 'get_class_space' attribute should be provided somewhere else in the class. The two values are joined with '::'.

    Accepts nothing

    Returns log_space . '::' . $self->get_class_space or just log_space if there is no return from 'get_class_space'

SUPPORT

TODO

    1. Nothing Yet

AUTHOR

Jed Lund
jandrew@cpan.org

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

DEPENDENCIES