Hades

 view release on metacpan or  search on metacpan

macro-fh.hades  view on Meta::CPAN

lib lib
tlib t
author LNATION
email email@lnation.org
version 0.27
Hades::Macro::FH base Hades::Macro {
	abstract { Hades macro helpers for FH }
	synopsis {
Quick summary of what the module does:

	Hades->run({
		eval => q|
			macro {
				FH [ alias => { read_file => [qw/rf/], write_file => [qw/wf/] } ]
			}
			Kosmos { 
				geras $file :t(Str) :d('path/to/file.txt') { 
					€rf($file);
					$content = 'limos';
					€wf($file, $content);
				}
			}
		|;
	});

	... generates ...

	package Kosmos;
	use strict;
	use warnings;
	our $VERSION = 0.01;

	sub new {
		my ( $cls, %args ) = ( shift(), scalar @_ == 1 ? %{ $_[0] } : @_ );
		my $self      = bless {}, $cls;
		my %accessors = ();
		for my $accessor ( keys %accessors ) {
			my $value
			    = $self->$accessor(
				defined $args{$accessor}
				? $args{$accessor}
				: $accessors{$accessor}->{default} );
			unless ( !$accessors{$accessor}->{required} || defined $value ) {
				die "$accessor accessor is required";
			}
		}
		return $self;
	}

	sub geras {
		my ( $self, $file ) = @_;
		$file = defined $file ? $file : 'path/to/file.txt';
		if ( !defined($file) || ref $file ) {
			$file = defined $file ? $file : 'undef';
			die qq{Str: invalid value $file for variable \$file in method geras};
		}

		open my $fh, "<", $file or die "cannot open file for reading: $!";
		my $content = do { local $/; <$fh> };
		close $fh;
		$content = 'limos';
		open my $wh, ">", $file or die "cannot open file for writing: $!";
		print $wh $content;
		close $wh;

	}



( run in 1.438 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )