Name

UR::Object::Command::Crud

Synopsis

Automatic generation of CRUD (create, list (read), update and delete plus copy) sub commands for UR objects.

Usage

Invoke building of of CRUD commands with UR::Object::Command::Crud->create_command_classes(%params). Example and config parameters are listed below.

Example

  • t/TestCrudClasses.pm Full test classes

  • example/muppet.pl The implementation of CRUD command below

muppet.pl

A script to manipulate muppets!

#!/usr/bin/env perl

use strict;
use warnings 'FATAL';

use Path::Class;

use lib file(__FILE__)->dir->parent->subdir('t')->stringify;
use lib file(__FILE__)->dir->parent->subdir('lib')->stringify;

use UR;
use UR::Object::Command::Crud;
use TestEnvCrud;

UR::Object::Command::Crud->create_command_classes(
    target_class => 'Test:Muppet',
    namespace => 'Muppet'
    target_name => 'muppet',
);

Muppet::Command->execute_with_shell_params_and_exit();

Sub Command Structure

Each CRUD function will get an in memory class created. These classes are used used for the command line interface. Under the update command, each object property will get its own command. If the relationship of the property is 'has many', there will be an add and remove command for the property.

script command structure

$ muppet.pl --help
Sub-commands for muppet.pl:
 copy         copy a muppet
 create       create muppets
 delete       delete muppet
 list         muppets
 update  ...  properties on muppets

update command tree

$ muppet.pl update -h
Sub-commands for muppet.pl update:
 best-friend       update muppets best_friend
 friends      ...  add/remove friends
 job               update muppets job
 name              update muppets name
 title             update muppets title

add/remove friends tree

$ muppet.pl update friends --help
Sub-commands for muppet.pl update friends:
 add       friends to muppets
 remove    friends from muppets

Config Parameters

*Optional unless noted*

Main Parameters

  • target_class (required): The class name of the objects to create CRUD commands.

  • target_name (optional): The space separated singular name of the objects. Default is to convert the class name from camel case to a space separated string. Our example, 'Test::Muppet' would be 'test muppet'. To make it just 'muppet', supply this value.

  • namespace (optional): The class name to be the namespace ofthe commadn structure. By default, command is added to the target class, then sub commands are then created from that class name. Use if wanting to adjust the command line structure abd naming. Ex: 'Muppet::Command'

  • sub_command_configs (optional): A HASH with command names as keys and config HASHes as values. See below for more details. Ex: { list => { show => 'id,name' } ... }

Sub Command Configs

*All params are optional*

All Sub Commands

  • skip: Skip, do not generate this sub command.

Create

exclude (optional): Exclude these properties, do not include them when creating an object.

List

show (optional): The default object properties to show. Give as a comma separated string. Ex: 'id,name,friends'. order_by (optional): The default order to list the objects in. The ID is the default. Give as string. Ex: 'name'.

Update

exclude (optional): Exclude these properties, do not make sub commmands for them. only_if_null (optional): Only allow updating of a property if it is null.

See Also

UR

Copyright

Copyright (c) 2012-2017 Eddie Belter <ebelter@wustl.edu>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See LICENSE for full details.