Coder Social home page Coder Social logo

perl-package-role-ini's Introduction

NAME

Package::Role::ini - Perl role for "ini" object that returns a Config::IniFiles object

SYNOPSIS

Configure INI file

/etc/my-package.ini
[section]
entry=my_value

Package

package My::Package;
use base qw{Package::New Package::Role::ini};

sub my_method {
  my $self  = shift;
  my $value = $self->ini->val('section', 'entry', 'default');
  return $value
}

DESCRIPTION

Perl role for "ini" object that returns a Config::IniFiles object against a default INI file name and location

OBJECT ACCESSORS

ini

Returns a lazy loaded Config::IniFiles object so that you can read settings from the INI file.

my $ini = $object->ini; #isa Config::IniFiles

METHODS

ini_file

Sets or returns the profile INI filename

my $file = $object->ini_file;
my $file = $object->ini_file("./my.ini");

Set on construction

my $object = My::Class->new(ini_file=>"./my.ini");

Default is the object lower case class name replacing :: with - and adding ".ini" extension. In other words, for the package My::Package the default location on Linux would be /etc/my-package.ini.

override in sub class

sub ini_file {"/path/my.ini"};

ini_path

Sets and returns the path for the INI file.

my $path = $object->ini_path;                  #isa Str
my $path = $object->ini_path("../other/path"); #isa Str

Default: C:\Windows on Windows-like systems that have Win32 installed Default: /etc on systems that have /etc Default: Sys::Path->sysconfdir on systems that Sys::Path installed Default: . otherwise

override in sub class

sub ini_path {"/my/path"};

ini_file_default

Default: lc(__PACKAGE__)=~s/::/-/g

ini_file_default_extension

Default: ini

SEE ALSO

Config::IniFiles, Package::New

AUTHOR

Michael R. Davis, mrdvt92

COPYRIGHT AND LICENSE

Copyright (C) 2020 by Michael R. Davis

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.3 or, at your option, any later version of Perl 5 you may have available.

perl-package-role-ini's People

Contributors

mrdvt92 avatar szabgab avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.