UR::Object::Command::Crud
Automatic generation of CRUD (create, list (read), update and delete plus copy) sub commands for UR objects.
Invoke building of of CRUD commands with UR::Object::Command::Crud->create_command_classes(%params). Example and config parameters are listed below.
t/TestCrudClasses.pm Full test classes
example/muppet.pl The implementation of CRUD command below
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();
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.
$ muppet.pl --help Sub-commands for muppet.pl: copy copy a muppet create create muppets delete delete muppet list muppets update ... properties on muppets
$ 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
$ muppet.pl update friends --help Sub-commands for muppet.pl update friends: add friends to muppets remove friends from muppets
*Optional unless noted*
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' } ... }
*All params are optional*
skip: Skip, do not generate this sub command.
exclude (optional): Exclude these properties, do not include them when creating an object.
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'.
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.
UR
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.
To install UR::Object::Command::Crud, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UR::Object::Command::Crud
CPAN shell
perl -MCPAN -e shell install UR::Object::Command::Crud
For more information on module installation, please visit the detailed CPAN module installation guide.