view release on metacpan or search on metacpan
lib/Module/Generic.pm view on Meta::CPAN
}
};
return( $new );
}
sub new_glob
{
my $that = shift( @_ );
my $class = ref( $that ) || $that;
no warnings 'once';
my $self = bless( \do{ local *FH } => $class );
*$self = {};
no strict 'refs';
if( defined( ${ "${class}\::LOG_DEBUG" } ) )
{
*$self->{log_debug} = ${ "${class}::LOG_DEBUG" };
}
if( Wanted::want( 'OBJECT' ) )
{
return( $self->init( @_ ) );
}
lib/Module/Generic.pm view on Meta::CPAN
no strict 'refs';
if( !ref( $self ) )
{
my $class = $self;
my $hash =
{
debug => ${ "${class}\::DEBUG" },
verbose => ${ "${class}\::VERBOSE" },
error => ${ "${class}\::ERROR" },
};
return( bless( $hash => $class ) );
}
elsif( ( Scalar::Util::reftype( $self ) // '' ) eq 'HASH' )
{
return( $self );
}
elsif( ( Scalar::Util::reftype( $self ) // '' ) eq 'GLOB' )
{
if( ref( *$self ) eq 'HASH' )
{
return( *$self );
lib/Module/Generic.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
};
}
unless( defined( &{"${class}\::FREEZE"} ) )
{
no warnings 'once';
*{"${class}::FREEZE"} = sub
{
lib/Module/Generic.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = bless( $hash => $class );
}
}
CORE::return( $new );
}
# NOTE: class function
# Used internally also in Module::Generic::Exception
sub UNIVERSAL::create_class
{
my $class = shift( @_ );
lib/Module/Generic/DateTime.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
sub TO_JSON
{
my $self = CORE::shift( @_ );
CORE::return( '' ) if( !$self->{dt} || !Scalar::Util::blessed( $self->{dt} ) );
CORE::return( $self->{dt}->stringify );
}
lib/Module/Generic/Dynamic.pm view on Meta::CPAN
our $VERSION = 'v1.3.0';
};
use strict;
no warnings 'redefine';
sub new
{
my $this = shift( @_ );
my $class = ref( $this ) || $this;
my $self = bless( {} => $class );
my $data = $self->{_data} = {};
# A Module::Generic object standard parameter
$self->{_data_repo} = '_data';
my $hash = {};
@_ = () if( scalar( @_ ) == 1 && !defined( $_[0] ) );
if( scalar( @_ ) == 1 && ( Scalar::Util::reftype( $_[0] ) // '' ) eq 'HASH' )
{
$hash = shift( @_ );
$self->{debug} = $DEBUG if( $DEBUG && !CORE::exists( $hash->{debug} ) );
}
lib/Module/Generic/Dynamic.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
sub TO_JSON
{
my $self = CORE::shift( @_ );
my $ref = { %$self };
CORE::delete( $ref->{_data} );
CORE::delete( $ref->{_data_repo} );
lib/Module/Generic/Exception.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
sub TO_JSON { return( shift->as_string ); }
sub UNIVERSAL::exception
{
my $class = shift( @_ );
my $me = __PACKAGE__;
lib/Module/Generic/File.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
sub TO_JSON { return( shift->filepath ); }
# NOTE: IO::File class modification
{
package
IO::File;
lib/Module/Generic/File.pm view on Meta::CPAN
return;
}
if( !( $file = $opts->{file} ) )
{
warn( "No file path was provided.\n" );
return;
}
no strict 'refs';
my $ref = \$file;
${$$ref} = $opts;
return( bless( $ref => $class ) );
}
sub FETCH
{
my $self = shift( @_ );
no strict 'refs';
my $fh;
if( !( $fh = ${$$self}->{fh} ) )
{
warn( "Filehandle is gone!\n" );
lib/Module/Generic/File/Cache.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
# NOTE: END
END
{
my $repo = Module::Generic::Global->new( 'cache' => __PACKAGE__, key => __PACKAGE__ );
my $repo_data = $repo->get;
return unless( defined( $repo_data ) && ref( $repo_data ) eq 'ARRAY' );
lib/Module/Generic/File/IO.pm view on Meta::CPAN
#
# sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
# NOTE: STORABLE_freeze_pre_processing called by Storable::Improved
sub STORABLE_freeze_pre_processing
{
my $self = CORE::shift( @_ );
my $class = CORE::ref( $self ) || $self;
my $args = $self->args;
# We change the glob object into a regular hash-based one to be Storable-friendly
my $this = CORE::bless( { args => $args, class => $class } => $class );
CORE::return( $this );
}
sub STORABLE_thaw_post_processing
{
my $self = CORE::shift( @_ );
my $args = ( CORE::exists( $self->{args} ) && CORE::ref( $self->{args} ) eq 'ARRAY' )
? $self->{args}
: [];
my $class = ( CORE::exists( $self->{class} ) && CORE::defined( $self->{class} ) && CORE::length( $self->{class} ) )
lib/Module/Generic/File/Mmap.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
if( CORE::defined( $cache_data ) &&
CORE::defined( $cache_file ) )
{
my $f = Module::Generic::File->new( $cache_file ) || do
{
warn( "Unable to get a file object for \"$cache_file\": ", Module::Generic::File->error, "\n" ) if( $self->_warnings_is_enabled() );
return( $new );
};
$new->{cache_file} = $f;
lib/Module/Generic/Finfo.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
sub TO_JSON { CORE::return( CORE::shift->filepath ); }
sub _datetime
{
my $self = shift( @_ );
my $t = shift( @_ );
lib/Module/Generic/Global.pm view on Meta::CPAN
$CALLER_INTERNAL->{'Module::Generic::Global::Exception'}++;
our $VERSION = 'v0.1.0';
};
use strict;
use warnings;
sub new
{
my $this = shift( @_ );
my $class = ref( $this ) || $this;
my $self = bless( {} => $class );
my $args = {};
if( @_ )
{
if( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'Module::Generic::Exception' ) )
{
$args->{object} = shift( @_ );
}
elsif( ref( $_[0] ) eq 'HASH' )
{
$args = shift( @_ );
lib/Module/Generic/Hash.pm view on Meta::CPAN
my %hash = ();
# This enables access to the hash just like a real hash while still the user an call our object methods
my $obj = tie( %hash, 'Module::Generic::TieHash', {
# disable => ['Module::Generic'],
debug => $DEBUG,
enable => 0,
# Should we allow objects to be used as key? Default to false
key_object => $KEY_OBJECT,
});
my $self = bless( \%hash => $class );
$obj->enable(1);
if( scalar( @_ ) == 1 )
{
my $data = shift( @_ );
if( defined( $data ) )
{
return( $that->error( "I was expecting an hash, but instead got '", ( $data // 'undef' ), "'." ) ) if( Scalar::Util::reftype( $data // '' ) ne 'HASH' );
my $tied = tied( %$data );
return( $that->error( "Hash provided is already tied to ", ref( $tied ), " and our package $class cannot use it, or it would disrupt the tie." ) ) if( $tied );
lib/Module/Generic/HeaderValue.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
1;
# NOTE: POD
__END__
=encoding utf-8
lib/Module/Generic/Iterator.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
1;
__END__
lib/Module/Generic/Null.pm view on Meta::CPAN
no warnings 'redefine';
sub new
{
my $this = shift( @_ );
my $class = ref( $this ) || $this;
my $error_object;
$error_object = shift( @_ ) if( Scalar::Util::blessed( $_[0] ) );
my $hash = ( @_ == 1 && ref( $_[0] ) ? shift( @_ ) : { @_ } );
$hash->{has_error} = $error_object;
return( bless( $hash => $class ) );
}
sub _obj_eq
{
no overloading;
my $self = shift( @_ );
my $other = shift( @_ );
if( Scalar::Util::blessed( $other ) && $other->isa( 'Module::Generic::Null' ) )
{
return( $self eq $other );
lib/Module/Generic/Null.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
1;
__END__
lib/Module/Generic/Number.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
sub TO_JSON { return( shift->as_string ); }
# NOTE: package Module::Generic::NumberSpecial
package Module::Generic::NumberSpecial;
BEGIN
{
lib/Module/Generic/Scalar.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
}
{
# NOTE: Module::Generic::Scalar::Tie class
package
Module::Generic::Scalar::Tie;
BEGIN
lib/Module/Generic/SharedMem.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
CORE::return( $new );
}
# NOTE: END
# END
# {
# my $shem_repo = Module::Generic::Global->new( 'shem_repo' => __PACKAGE__, key => __PACKAGE__ );
# $shem_repo->lock;
# my $all_shem = $shem_repo->get // [];
lib/Module/Generic/SharedMem.pm view on Meta::CPAN
my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
my $array = CORE::ref( $ref ) eq 'ARRAY' ? $ref : [];
# Storable pattern requires to modify the object it created rather than returning a new one
if( CORE::ref( $self ) )
{
@$self = @$array;
CORE::return( $self );
}
else
{
my $new = bless( $array => $class );
CORE::return( $new );
}
}
sub TO_JSON { CORE::return( [ @{$_[0]} ] ); }
}
# NOTE: Module::Generic::SemStat class
{
package
lib/Module/Generic/SharedMem.pm view on Meta::CPAN
my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
my $array = CORE::ref( $ref ) eq 'ARRAY' ? $ref : [];
# Storable pattern requires to modify the object it created rather than returning a new one
if( CORE::ref( $self ) )
{
@$self = @$array;
CORE::return( $self );
}
else
{
my $new = bless( $array => $class );
CORE::return( $new );
}
}
sub TO_JSON { CORE::return( [ @{$_[0]} ] ); }
}
1;
__END__
lib/Module/Generic/SharedMemXS.pm view on Meta::CPAN
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = CORE::bless( $hash => $class );
}
if( $was_opened )
{
my $size = ( defined( $new->{size} ) && length( $new->{size} ) ) ? $new->{size} : SHM_BUFSIZ;
my $flags = ( defined( $new->{flags} ) && length( $new->{flags} ) ) ? $new->{flags} : &IPC::SysV::S_IRWXU;
$flags |= &IPC::SysV::IPC_CREAT if( defined( $new->{create} ) && $new->{create} );
my $key = $new->{key};
# try-catch
local $@;
eval
t/lib/Test/Apache2/MG.pm view on Meta::CPAN
$r->log_error( "$class: MG_DEBUG value set to '$debug'" );
Apache2::RequestUtil->request( $r );
Module::Generic::Global->cleanup_register( $r );
# Call the inner module to instantiate a new object
my $obj = MyObject->new( request => $r, debug => $debug );
if( !$obj )
{
$r->log_error( "$class: Error instantiating Apache2::API object: ", MyObject->error );
return( Apache2::Const::HTTP_INTERNAL_SERVER_ERROR );
}
my $self = bless( { request => $r, _object => $obj, debug => $debug } => $class );
return( $self->process );
}
sub dummy_error
{
my $self = shift( @_ );
my $obj = $self->_object || die( "No object." );
$obj->error({ message => 'Oh no!', code => 400 });
return( $self->reply_enhanced({ message => $obj->error->message, code => $obj->error->code }) );
}