App-Spec

 view release on metacpan or  search on metacpan

t/lib/App/Spec/Example/MyApp.pm  view on Meta::CPAN

package App::Spec::Example::MyApp;
use warnings;
use strict;
use 5.010;

use Ref::Util qw/ is_arrayref is_hashref /;

use base 'App::Spec::Run::Cmd';

sub _dump_hash {
    my ($self, $hash) = @_;
    my @strings;
    for my $key (sort keys %$hash) {
        next unless defined $hash->{ $key };
        my $value = $hash->{ $key };
        if (is_hashref($value)) {
            for my $key2 (sort keys %$value) {
                push @strings, "$key=($key2=$value->{ $key2 })";
            }
        }
        else {
            push @strings, "$key=$value";
        }
    }
    return join ",", @strings;
}

sub cook {
    my ($self, $run) = @_;
    my $param = $run->parameters;
    my $opt = $run->options;
    if ($ENV{PERL5_APPSPECRUN_TEST}) {
        $run->out("Subcommands: cook");
        $run->out("Options: " . $self->_dump_hash($opt));
        $run->out("Parameters: " .  $self->_dump_hash($param));
        return;
    }

    my @with;
    my $with = $opt->{with} // '';
    if ($with eq "cow milk") {
        die "Sorry, no cow milk today. go vegan\n";
    }
    push @with, $with if $with;
    push @with, "sugar" if $opt->{sugar};

    $run->out("Starting to cook $param->{drink}"
    . (@with ? " with ". (join " and ", @with) : ''));
}

my %countries = (
    Austria => {
      Vienna => { weather => "sunny =)", temperature => 23 },
      Salzburg => { weather => "rainy =(", temperature => 13 },
    },
    Germany => {
      Berlin => { weather => "snow =)", temperature => -2 },
      Hamburg => { weather => "sunny =)", temperature => 19 },
      Frankfurt => { weather => "rainy =(", temperature => 23 },
    },
    Netherlands => {
      Amsterdam => { weather => "rainy =(", temperature => 17 },
      Echt => { weather => "sunny =)", temperature => 37 },
    },
);

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.850 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )