NAME

PDK::Content::Dumper - A Moose role for debugging and file operations

SYNOPSIS

package MyApp;
use Moose;
with 'PDK::Content::Dumper';

# Now your class has debug and file writing capabilities
$self->dump("Debug message");
$self->write_file($config, "config.txt");

DESCRIPTION

PDK::Content::Dumper is a Moose role that provides debugging and file operation capabilities. It offers methods for outputting debug information and writing configurations to files, with customizable debug levels and working directories.

ATTRIBUTES

month

A read-only attribute that returns the current month in YYYY-MM format.

date

A read-only attribute that returns the current date in YYYY-MM-DD format.

workdir

A read-write attribute representing the working directory. It prioritizes the PDK_CONTENT_HOME environment variable, defaulting to the user's home directory if not set.

debug

A read-write attribute representing the debug level. It's set from the PDK_CONTENT_DEBUG environment variable, defaulting to 0 if not set.

METHODS

now

my $timestamp = $self->now();

Returns the current timestamp in YYYY-MM-DD HH:MM:SS format.

dump($message)

$self->dump("Debug information");

Outputs debug information based on the current debug level. If debug level is 1, it prints to console. If greater than 1, it writes to a file.

write_file($config, $name)

$self->write_file($config_content, "config_file.txt");

Writes the given configuration content to a file in the working directory. Returns a hashref with a 'success' key.

PRIVATE METHODS

_debug_init($message)

An internal method used for initializing debug output. It prints to STDERR if PDK_CONTENT_DEBUG is set.

ENVIRONMENT

PDK_CONTENT_HOME

Sets the working directory for file operations.

PDK_CONTENT_DEBUG

Sets the debug level. 0 disables debug output, 1 enables console output, and >1 enables file output.

DEPENDENCIES

This module requires the following modules:

  • Moose::Role

  • Carp

  • File::Path

  • namespace::autoclean

AUTHOR

WENWU YAN <968828@gmail.com>

LICENSE

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.