Hyper::Developer::Generator::Control - abstract base class which offers


Hyper-Developer documentation Contained in the Hyper-Developer distribution.

Index


Code Index:

NAME

Top

Hyper::Developer::Generator::Control - abstract base class which offers a special create method for Control generation.

VERSION

Top

This document describes Hyper::Developer::Generator::Control 0.01

SYNOPSIS

Top

    package Hyper::Developer::Generator::Control::ContainerFlow;
    use base qw(Hyper::Developer::Generator::Control);

    1;

DESCRIPTION

Top

ATTRIBUTES

Top

usecase :name
service :name
type :set
sub_path :set
suffix :set

SUBROUTINES/METHODS

Top

create

Top

    $object->create({
        name     => 'filename_without_suffix', # MANDATORY
        template => '/template/to/use.tpl',
        force    => 'boolean value, overwrite existing file?'
        data     => {
            what => 'ever',
            passed => 'to template',
        },
    });

Calls the Hyper::Developer::Generator::create method with some special. This method is only important for out code generator maintainers.

DIAGNOSTICS

Top

CONFIGURATION AND ENVIRONMENT

Top

DEPENDENCIES

Top

INCOMPATIBILITIES

Top

BUGS AND LIMITATIONS

Top

RCS INFORMATIONS

Top

Last changed by

$Author: ac0v $

Id

$Id: Control.pm 333 2008-02-18 22:59:27Z ac0v $

Revision

$Revision: 333 $

Date

$Date: 2008-02-18 23:59:27 +0100 (Mon, 18 Feb 2008) $

HeadURL

$HeadURL: http://svn.hyper-framework.org/Hyper/Hyper-Developer/branches/0.07/lib/Hyper/Developer/Generator/Control.pm $

AUTHOR

Top

Andreas Specht <ACID@cpan.org>

LICENSE AND COPYRIGHT

Top


Hyper-Developer documentation Contained in the Hyper-Developer distribution.

package Hyper::Developer::Generator::Control;

use strict;
use warnings;
use version; our $VERSION = qv('0.01');

use base qw(Hyper::Developer::Generator);
use Class::Std;
use Hyper::Functions;
use File::Path ();
use Hyper::Error;

my %usecase_of  :ATTR(:name<usecase>);
my %service_of  :ATTR(:name<service>);

# spec for gen. target
my %type_of     :ATTR(:set<type>);
my %sub_path_of :ATTR(:set<sub_path>);
my %suffix_of   :ATTR(:set<suffix>);

sub create {
    my $self    = shift;
    my $arg_ref = shift || {}; # name, template, force, data
    my $ident   = ident $self;

    # $arg_ref->{name} => mandatory

    my $path = $self->get_base_path()
      . '/' . Hyper::Functions::get_path_for($type_of{$ident})
      . '/' . $self->get_namespace()
      . '/' . $sub_path_of{$ident}
      . '/' . $self->get_service();
    my $file = "$path/$arg_ref->{name}.$suffix_of{$ident}";

    # TODO modify to use IO::File->new( $file, O_CREAT | O_WRONLY | O_EXCL)
    # instead of "warn if -e $file";
    # open my $fh, $file if ( not (-e $file) )
    # is a race condition: If someone manages to put a file in place
    # between -e and open, we clobber an existing file...

    # return if file exists and force isn't set
    my $force = exists $arg_ref->{force}
        ? $arg_ref->{force}
        : $self->get_force();
    if ( ! $force && -e $file ) {
        warn "can't generate code, destination file >$file< exists";
        return $self;
    }

    File::Path::mkpath([$path], 0, 0770);

    my $template = $self->get_template();
    $template->process(
        $arg_ref->{template},
        { data => $arg_ref->{data},
          this => $self,
          name => $arg_ref->{name},
        },
        $file,
    ) or throw($template->error());

    return $self;
}

1;

__END__