Aion-Format

 view release on metacpan or  search on metacpan

LICENSE  view on Meta::CPAN

for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.

  Conveying under any other circumstances is permitted solely under
the conditions stated below.  Sublicensing is not allowed; section 10
makes it unnecessary.

  3. Protecting Users' Legal Rights From Anti-Circumvention Law.

  No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.

  When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.

  4. Conveying Verbatim Copies.

  You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.

README.md  view on Meta::CPAN

Как `coloring`, но печатает отформатированную строку на стандартный вывод.

## warncolor ($format, @params)

Как `coloring`, но печатает отформатированную строку в `STDERR`.

```perl
trapperr { warncolor "#{green}ACCESS#r %i\n", 6 }  # => \e[32mACCESS\e[0m 6\n
```

## accesslog ($format, @params)

Пишет в STDOUT используя для форматирования функцию `coloring` и добавляет префикс с датой-временем.

```perl
trappout { accesslog "#{green}ACCESS#r %i\n", 6 }  # ~> \[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[32mACCESS\e\[0m 6\n
```

## errorlog ($format, @params)

Пишет в **STDERR** используя для форматирования функцию `coloring` и добавляет префикс с датой-временем.

```perl
trapperr { errorlog "#{red}ERROR#r %i\n", 6 }  # ~> \[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[31mERROR\e\[0m 6\n
```

## p ($target; %properties)

`p` из Data::Printer с предустановленными настройками.

Вместо неудобного первого параметра используется просто скаляр.

Необязательный параметр `%properties` позволяет перекрывать настройки. 

lib/Aion/Format.md  view on Meta::CPAN

Как `coloring`, но печатает отформатированную строку на стандартный вывод.

## warncolor ($format, @params)

Как `coloring`, но печатает отформатированную строку в `STDERR`.

```perl
trapperr { warncolor "#{green}ACCESS#r %i\n", 6 }  # => \e[32mACCESS\e[0m 6\n
```

## accesslog ($format, @params)

Пишет в STDOUT используя для форматирования функцию `coloring` и добавляет префикс с датой-временем.

```perl
trappout { accesslog "#{green}ACCESS#r %i\n", 6 }  # ~> \[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[32mACCESS\e\[0m 6\n
```

## errorlog ($format, @params)

Пишет в **STDERR** используя для форматирования функцию `coloring` и добавляет префикс с датой-временем.

```perl
trapperr { errorlog "#{red}ERROR#r %i\n", 6 }  # ~> \[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[31mERROR\e\[0m 6\n
```

## p ($target; %properties)

`p` из Data::Printer с предустановленными настройками.

Вместо неудобного первого параметра используется просто скаляр.

Необязательный параметр `%properties` позволяет перекрывать настройки. 

lib/Aion/Format.pm  view on Meta::CPAN

sub printcolor(@) {
	print coloring @_
}

# Печатает в STDERR вывод coloring
sub warncolor(@) {
	print STDERR coloring @_
}

# Для крона: Пишет в STDOUT
sub accesslog(@) {
	print "[", POSIX::strftime("%F %T", localtime), "] ", coloring @_;
}

# Для крона: Пишет в STDIN
sub errorlog(@) {
	print STDERR "[", POSIX::strftime("%F %T", localtime), "] ", coloring @_;
}


#@category Преобразования

# Проводит соответствия
#
# replace "...", qr/.../ => sub {...}, ...
#

lib/Aion/Format.pm  view on Meta::CPAN

=head2 printcolor ($format, @params)

Like C<coloring>, but prints the formatted string to standard output.

=head2 warncolor ($format, @params)

Like C<coloring>, but prints the formatted string to C<STDERR>.

	trapperr { warncolor "#{green}ACCESS#r %i\n", 6 }  # => \e[32mACCESS\e[0m 6\n

=head2 accesslog ($format, @params)

Writes to STDOUT using the C<coloring> function for formatting and adds a date-time prefix.

	trappout { accesslog "#{green}ACCESS#r %i\n", 6 }  # ~> \[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[32mACCESS\e\[0m 6\n

=head2 errorlog ($format, @params)

Writes to B<STDERR> using the C<coloring> function for formatting and adds a date-time prefix.

	trapperr { errorlog "#{red}ERROR#r %i\n", 6 }  # ~> \[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[31mERROR\e\[0m 6\n

=head2 p ($target; %properties)

C<p> from Data::Printer with preset settings.

Instead of the inconvenient first parameter, a simple scalar is used.

The optional C<%properties> parameter allows you to override settings.

	trapperr { p +{cat => 123} } # ~> cat.+123

t/aion/format.t  view on Meta::CPAN

# Как `coloring`, но печатает отформатированную строку на стандартный вывод.
# 
# ## warncolor ($format, @params)
# 
# Как `coloring`, но печатает отформатированную строку в `STDERR`.
# 
::done_testing; }; subtest 'warncolor ($format, @params)' => sub { 
local ($::_g0 = do {trapperr { warncolor "#{green}ACCESS#r %i\n", 6 }}, $::_e0 = "\e[32mACCESS\e[0m 6\n"); ::ok $::_g0 eq $::_e0, 'trapperr { warncolor "#{green}ACCESS#r %i\n", 6 }  # => \e[32mACCESS\e[0m 6\n' or ::diag ::_string_diff($::_g0, $::_e0)...

# 
# ## accesslog ($format, @params)
# 
# Пишет в STDOUT используя для форматирования функцию `coloring` и добавляет префикс с датой-временем.
# 
::done_testing; }; subtest 'accesslog ($format, @params)' => sub { 
::like scalar do {trappout { accesslog "#{green}ACCESS#r %i\n", 6 }}, qr{\[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[32mACCESS\e\[0m 6\n}, 'trappout { accesslog "#{green}ACCESS#r %i\n", 6 }  # ~> \[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[32mACCESS\e\[0m ...

# 
# ## errorlog ($format, @params)
# 
# Пишет в **STDERR** используя для форматирования функцию `coloring` и добавляет префикс с датой-временем.
# 
::done_testing; }; subtest 'errorlog ($format, @params)' => sub { 
::like scalar do {trapperr { errorlog "#{red}ERROR#r %i\n", 6 }}, qr{\[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[31mERROR\e\[0m 6\n}, 'trapperr { errorlog "#{red}ERROR#r %i\n", 6 }  # ~> \[\d{4}-\d{2}-\d{2} \d\d:\d\d:\d\d\] \e\[31mERROR\e\[0m 6\n'; unde...

# 
# ## p ($target; %properties)
# 
# `p` из Data::Printer с предустановленными настройками.
# 
# Вместо неудобного первого параметра используется просто скаляр.
# 
# Необязательный параметр `%properties` позволяет перекрывать настройки. 
# 



( run in 0.630 second using v1.01-cache-2.11-cpan-0371d4a6215 )