« Jifty/Plugin/Authentication/Password/Action/SendAccountConfirmation.pm
↑ Summary
Jifty/RightsFrom.pm »
| 1 | package Jifty::Script::Env; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | use base qw/Jifty::Script/; | ||
| 7 | |||
| 8 | use Scalar::Util (); | ||
| 9 | |||
| 10 | use Jifty::Config; | ||
| 11 | use Jifty::YAML; | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | Jifty::Script::Env - access the Jifty environment | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | jifty env <Class> <method> [arguments] | ||
| 20 | |||
| 21 | jifty env Util share_root | ||
| 22 | jifty env 'Util->share_root' | ||
| 23 | jifty env Util.share_root | ||
| 24 | |||
| 25 | =head1 DESCRIPTION | ||
| 26 | |||
| 27 | Loads Jifty and your configuration, allowing you to verify and examine | ||
| 28 | your setup. | ||
| 29 | |||
| 30 | Loads Jifty::Class and calls method on it, providing shortcuts for | ||
| 31 | things like: | ||
| 32 | |||
| 33 | perl -MJifty::Util -e 'print Jifty::Util->share_root, "\n";' | ||
| 34 | |||
| 35 | The class and method can be combined with a '->' But, unquoted '>' is a | ||
| 36 | redirect so simply use the '-' or '.' characters. | ||
| 37 | |||
| 38 | jifty env Util share_root | ||
| 39 | jifty env 'Util->share_root' | ||
| 40 | jifty env Util.share_root | ||
| 41 | |||
| 42 | You may chain accessors. A leading dot also means the class is Jifty. | ||
| 43 | |||
| 44 | jifty env Jifty.config.framework ApplicationName | ||
| 45 | jifty env .config.framework ApplicationName | ||
| 46 | |||
| 47 | With no arguments, acts as 'C<jifty env Jifty.config.stash>'. | ||
| 48 | |||
| 49 | =head2 options | ||
| 50 | |||
| 51 | This script has no specific options now. Maybe it will have | ||
| 52 | some command lines options in the future. | ||
| 53 | |||
| 54 | =over 8 | ||
| 55 | |||
| 56 | =item B<--help> | ||
| 57 | |||
| 58 | Print a brief help message and exits. | ||
| 59 | |||
| 60 | =item B<--man> | ||
| 61 | |||
| 62 | Prints the manual page and exits. | ||
| 63 | |||
| 64 | =back | ||
| 65 | |||
| 66 | =head1 METHODS | ||
| 67 | |||
| 68 | =head2 run | ||
| 69 | |||
| 70 | Prints whatever the user asked for. | ||
| 71 | |||
| 72 | =cut | ||
| 73 | |||
| 74 | sub run { | ||
| 75 | my $self = shift; | ||
| 76 | my (@args) = @_; | ||
| 77 | |||
| 78 | $self->print_help; | ||
| 79 | |||
| 80 | Jifty->new(); | ||
| 81 | |||
| 82 | unless(@args) { | ||
| 83 | $self->run('Jifty.config.stash'); | ||
| 84 | print "\nSee also `jifty env --help`\n"; | ||
| 85 | return; | ||
| 86 | } | ||
| 87 | |||
| 88 | my ($class, $method, @and) = split(/(?:->?|\.)/, shift(@args)); | ||
| 89 | $class ||= 'Jifty'; | ||
| 90 | $method ||= shift(@args); | ||
| 91 | |||
| 92 | my @ans; | ||
| 93 | |||
| 94 | # enable Jifty.config.stash usage | ||
| 95 | unless($class eq 'Jifty') { | ||
| 96 | $class = 'Jifty::' . $class; | ||
| 97 | eval("require $class") or die $@; | ||
| 98 | } | ||
| 99 | |||
| 100 | # walk down the chain of methods | ||
| 101 | unshift(@and, $method); | ||
| 102 | $method = pop(@and); | ||
| 103 | while(my $attrib = shift(@and)) { | ||
| 104 | $class = $class->$attrib; | ||
| 105 | } | ||
| 106 | |||
| 107 | @ans = $class->$method(@args); | ||
| 108 | |||
| 109 | # if something in the answer is a reference, just dump | ||
| 110 | if(grep({Scalar::Util::reftype($_)} @ans)) { | ||
| 111 | print Jifty::YAML::Dump(\@ans); | ||
| 112 | } | ||
| 113 | else { | ||
| 114 | print join("\n", @ans, ''); | ||
| 115 | } | ||
| 116 | |||
| 117 | |||
| 118 | } # end run | ||
| 119 | |||
| 120 | # original author: Eric Wilhelm | ||
| 121 | |||
| 122 | 1; | ||
| 123 | # vim:ts=4:sw=4:et:sta |