« blib/lib/UR/Namespace/Command/Test/Compile.pm
↑ Summary
blib/lib/UR/Namespace/Command/Update/RewriteClassHeader.pm »
| 1 | |||
| 2 | package UR::Namespace::Command::Test::Eval; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use UR; | ||
| 7 | our $VERSION = "0.46"; # UR $VERSION; | ||
| 8 | |||
| 9 | UR::Object::Type->define( | ||
| 10 | class_name => __PACKAGE__, | ||
| 11 | is => 'UR::Namespace::Command::Base', | ||
| 12 | has => [ | ||
| 13 | bare_args => { | ||
| 14 | is_optional => 1, | ||
| 15 | is_many => 1, | ||
| 16 | shell_args_position => 1 | ||
| 17 | } | ||
| 18 | ] | ||
| 19 | ); | ||
| 20 | |||
| 21 | |||
| 22 | sub help_brief { | ||
| 23 | "Evaluate a string of Perl source"; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub help_synopsis { | ||
| 27 | return <<'EOS'; | ||
| 28 | ur test eval 'print "hello\n"' | ||
| 29 | ur test eval 'print "hello\n"' 'print "goodbye\n"' | ||
| 30 | ur test eval 'print "Testing in the " . \$self->namespace_name . " namespace.\n"' | ||
| 31 | EOS | ||
| 32 | } | ||
| 33 | |||
| 34 | sub help_detail { | ||
| 35 | return <<EOS; | ||
| 36 | This command is for testing and debugging. It simply eval's the Perl | ||
| 37 | source supplied on the command line, after using the current namespace. | ||
| 38 | |||
| 39 | A \$self object is in scope representing the current context. | ||
| 40 | EOS | ||
| 41 | } | ||
| 42 | |||
| 43 | sub execute { | ||
| 44 | my $self = shift; | ||
| 45 | for my $src ($self->bare_args) { | ||
| 46 | eval "use Data::Dumper; use YAML; no strict; no warnings; \n" . $src; | ||
| 47 | if ($@) { | ||
| 48 | print STDERR "EXCEPTION:\n$@"; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | return 1; | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; |