Permalink
Browse files

Some minor improvements, nevermind

  • Loading branch information...
Vladimir Melnik
Vladimir Melnik committed Jan 18, 2016
1 parent 4b3f9a8 commit 6267a0a14b0a920c395cf36aaba2a01405b170fa
@@ -3,6 +3,9 @@
use ExtUtils::MakeMaker;
WriteMakefile(
ABSTRACT_FROM => 'lib/MonkeyMan.pm',
AUTHOR => 'Volodymyr Melnyk <vladimir@melnik.net.ua>',
LICENSE => 'Apache',
NAME => 'MonkeyMan',
VERSION_FROM => 'lib/MonkeyMan.pm',
test => {
@@ -8,9 +8,16 @@ Code
- on `2016.01.17` by `melnik13`
- [ ] Build a proper `Makefile`
- suggested on `2016.01.17` by `melnik13`
- [ ] Use `MonkeyMan::CloudStack::Types::*` types everywhere
- on `2016.01.18` by `melnik13`
- [x] Use `%::*::_magic_words in t/qxp.t`
- suggested on `2016.01.17` by `melnik13`
- completed on `2016.01.17`
Functionality
-------------
- [ ] Port bin/makesnapshots.pl from the `stables` branch to
the `dev_melnik13_v3` one
- suggested on `2016.01.18` by `melnik13`
@@ -12,47 +12,50 @@
use MonkeyMan::Constants qw(:directories);
use MonkeyMan::Exception;
MonkeyMan->new(
use autodie qw(open close);
use Cwd qw(abs_path);
use File::Find;
use File::Path qw(make_path);
use Pod::Markdown::Github;
my $mm = MonkeyMan->new(
app_code => undef,
app_name => 'pod2mkd',
app_description => 'Updates markdown documentation',
app_version => 'v0.0.1',
app_description => 'Converts MonkeyMan documentation from POD to Markdown',
app_version => 'v1.0.0',
app_usage_help => sub { <<__END_OF_APP_USAGE_HELP__ },
Understands the following parameters:
-m, --markdown-direcrory <dir>
[req] Where to put Markdown results
-p, --pod-directories <dir>
[req] [mul] Where POD sources are located
[req] [mul] Where to get POD sources to be converted
-r, --pod-root-directory <dir>
[opt] Where is the directory tree's root
-m, --markdown-direcrory <dir>
[req] Where to put MD results
[opt] Where is the directory tree's root (it's needed to build
the directory tree in the Markdown directory)
-f, --force
[opt] To ignore mtime
[opt] To ignore modification time (renews everything)
__END_OF_APP_USAGE_HELP__
parameters_to_get => {
'p|pod-directories=s@' => 'pod_directories',
'r|pod-root-directory=s' => 'pod_root_directory',
'm|markdown-directory=s' => 'markdown_directory',
'f|force' => 'force'
},
app_code => sub {
### THE CODE GOES HERE ###
use autodie qw(open close);
use Cwd qw(abs_path);
use File::Find;
use File::Path qw(make_path);
use Pod::Markdown::Github;
}
);
my $mm = shift;
my $log = $mm->get_logger;
my $conf = $mm->get_configuration;
my $parameters = $mm->get_parameters;
# So, do we know what directories shall we proceed?
unless(defined($parameters->get_pod_directories)) {
MonkeyMan::Exception->throwf("No POD directories defined");
}
# And do we know what is the project's root directory? Or shall we decide?
my $pod_root_directoryname = abs_path(
defined($parameters->get_pod_root_directory) ?
$parameters->get_pod_root_directory :
@@ -63,6 +66,8 @@
}
$log->tracef("The project's root directory is %s", $pod_root_directoryname);
# Well, do we know where to put the results of our work
my $doc_root_directoryname = abs_path(
defined($parameters->get_markdown_directory) ?
$parameters->get_markdown_directory :
@@ -73,20 +78,23 @@
}
$log->tracef("The documentation root directory is %s", $doc_root_directoryname);
# Okay, let's run it!
foreach my $pod_directoryname (@{ $parameters->get_pod_directories }) {
$pod_directoryname = abs_path($pod_directoryname);
$log->debugf("Processing the %s directory", $pod_directoryname);
find({
follow => 1,
wanted => sub {
# So, we've found a file...
my $pod_filename_short = $_;
my $pod_filename_short_new = $pod_filename_short;
if($pod_filename_short_new =~ s#^(.+\.p[lm])$#$1.md#) {
if($pod_filename_short_new =~ s#^(.+\.(p[lm]|pod|t))$#$1.md#) {
my $pod_filename_long = $File::Find::name;
unless($pod_filename_long =~ qr#^\Q${pod_root_directoryname}\E(/(.+)/)?\Q${pod_filename_short}\E$#) {
$log->warnf("The %s file didn't match the verifying regex", $pod_filename_long);
} else {
$log->debugf("Have found the %s file", $pod_filename_long);
$log->debugf("Found the %s file", $pod_filename_long);
my $mkd_directoryname = sprintf("%s/%s", $doc_root_directoryname, $2);
my $mkd_filename_long = sprintf("%s/%s", $mkd_directoryname, $pod_filename_short_new);
my $pod_file_mtime = (stat($pod_filename_long))[9];
@@ -103,7 +111,7 @@
open(my $mkd_filehandle, '>', $mkd_filename_long);
print($mkd_filehandle $mkd_string);
close($mkd_filehandle);
$log->infof("%s --> %s",
$log->infof("%s converted to %s",
$pod_filename_long,
$mkd_filename_long
);
@@ -115,7 +123,3 @@
}, $pod_directoryname);
}
### THE CODE STOPS ###
}
);
@@ -55,7 +55,7 @@ sub MyCoolApplication {
}
# > apps/cool/mine.pl -d 01234567-89ab-cdef-fedc-ba9876543210
# 2040/04/20 04:20:00 [I] [main] The virtual machine's ID is 01234567-dead-beef-cafe-899123456789 - got as [MonkeyMan::CloudStack::API::Element::VirtualMachine@0xdeadbee/badcaffefeeddeafbeefbabedeadface]
# 2040/04/20 04:20:00 [I] [main] The virtual machine's ID is 01234567-dead-beef-cafe-899123456789 - got as [MonkeyMan::CloudStack::API::Element::VirtualMachine@0xdeadbee/badcaffefeeddeafbeefbabedeadface]
#
# Hope you'll enjoy it :)
#
@@ -256,7 +256,7 @@ This method queries the DOM (as [XML::LibXML::Document](https://metacpan.org/pod
with the XPath-query provided.
```perl
$dom = $api->run(
$dom = $api->run_command(
command => 'listVirtualMachines',
listAll => 'true'
);
@@ -60,7 +60,7 @@ with high-level Perl5-applications.
}
# > apps/cool/mine.pl -d 01234567-89ab-cdef-fedc-ba9876543210
# 2040/04/20 04:20:00 [I] [main] The virtual machine's ID is 01234567-dead-beef-cafe-899123456789 - got as [MonkeyMan::CloudStack::API::Element::VirtualMachine@0xdeadbee/badcaffefeeddeafbeefbabedeadface]
# 2040/04/20 04:20:00 [I] [main] The virtual machine's ID is 01234567-dead-beef-cafe-899123456789 - got as [MonkeyMan::CloudStack::API::Element::VirtualMachine@0xdeadbee/badcaffefeeddeafbeefbabedeadface]
#
# Hope you'll enjoy it :)
#
@@ -123,12 +123,12 @@ method BUILD(...) {
$self->_app_finish;
}
}
END {
my $mm = MonkeyMan->instance;
$mm->_mm_shutdown;
$mm->get_logger->debugf("<%s> Goodbye world!", $mm->get_time_passed_formatted);
}
END {
my $mm = MonkeyMan->instance;
$mm->_mm_shutdown;
$mm->get_logger->debugf("<%s> Goodbye world!", $mm->get_time_passed_formatted);
}
method BUILDARGS(...) {
@@ -40,7 +40,7 @@ use namespace::autoclean;
with 'MonkeyMan::CloudStack::Essentials';
with 'MonkeyMan::Roles::WithTimer';
use MonkeyMan::CloudStack::Types qw(ElementType);
use MonkeyMan::CloudStack::Types qw(ElementType ReturnAs);
use MonkeyMan::Constants qw(:cloudstack);
use MonkeyMan::Utils qw(mm_load_package);
use MonkeyMan::Exception qw(
@@ -644,11 +644,11 @@ This method finds infrastructure elements by the criterions defined.
=cut
method get_elements(
MonkeyMan::CloudStack::Types::ElementType :$type!,
Maybe[Str] :$return_as = 'element',
Maybe[HashRef] :$criterions,
Maybe[ArrayRef[Str]] :$xpaths,
Maybe[ArrayRef[XML::LibXML::Document]] :$doms,
MonkeyMan::CloudStack::Types::ElementType :$type!,
Maybe[MonkeyMan::CloudStack::Types::ReturnAs] :$return_as = 'element',
Maybe[HashRef] :$criterions,
Maybe[ArrayRef[Str]] :$xpaths,
Maybe[ArrayRef[XML::LibXML::Document]] :$doms,
) {
my $logger = $self->get_cloudstack->get_monkeyman->get_logger;
@@ -760,9 +760,9 @@ C<MonkeyMan::CloudStack::API::Element::TYPE> objects.
=cut
method qxp(
Str :$query!,
Str :$query!,
XML::LibXML::Document :$dom!, # DON'T ADD SPACES HERE!
Maybe[Str] :$return_as,
Maybe[MonkeyMan::CloudStack::Types::ReturnAs] :$return_as
) {
my $logger = $self->get_cloudstack->get_monkeyman->get_logger;
@@ -304,6 +304,32 @@ method is_dom_expired(Maybe[Str] $best_before) {
has 'id' => (
is => 'rw',
isa => 'Maybe[Str]',
reader => 'get_id',
writer => '_set_id',
predicate => 'has_id',
builder => '_build_id',
lazy => 1
);
method _build_id {
$self->get_id;
}
around 'get_id' => sub {
my $orig = shift;
my $self = shift;
return(($self->qxp(
query => '/id',
return_as => 'value'
))[0]);
};
method get_related(
Str :$type!,
Maybe[Str] :$best_before
@@ -346,31 +372,7 @@ method get_related(
has 'id' => (
is => 'rw',
isa => 'Maybe[Str]',
reader => 'get_id',
writer => '_set_id',
predicate => 'has_id',
builder => '_build_id',
lazy => 1
);
method _build_id {
$self->get_id;
}
around 'get_id' => sub {
my $orig = shift;
my $self = shift;
return(($self->qxp(
query => '/id',
return_as => 'value'
))[0]);
};
# Some proxy-like methods goes here...
method qxp(
Str :$query!,
@@ -395,6 +397,14 @@ method qxp(
}
method criterions_to_parameters(...) {
my @results = $self->get_api->criterions_to_parameters(
$self->get_type,
@_
);
return(@results);
}
1;
@@ -1,26 +1,40 @@
package MonkeyMan::CloudStack::Types;
#FIXME: MonkeyMan::CloudStack::API::Types?
use strict;
use warnings;
our @_types_known = qw(
VirtualMachine
Domain
);
use MooseX::Types -declare => [
qw(
ElementType
ReturnAs
)
];
use MooseX::Types::Moose qw(Str);
no strict 'refs';
our @_ElementType_values = qw(
VirtualMachine
Domain
);
subtype ElementType,
as Str,
where { grep(@{'::' . __PACKAGE__ . '::_types_known'}, $_); },
message { "ElementType isn't valid" };
where { my $v = $_; grep({ $_ eq $v} @_ElementType_values); },
message { "This ElementType isn't valid" };
our @_ReturnAs_regexps = qw(
^dom$
^value$
^element(:?\[.+\])?$
^id(:?\[.+\])?$
);
subtype ReturnAs,
as Str,
where { my $v = $_; grep({ $v =~ qr/$_/ } @_ReturnAs_regexps); },
message { "This ReturnAs isn't valid" };
@@ -33,7 +33,7 @@ after install_accessors => sub {
my $handy_default = $handy->{'default'};
confess("The default slot of the handy isn't defined")
unless(defined($handy_name));
unless(defined($handy_default));
my $handy_strict = $handy->{'strict'};
confess("The strictness of the handy isn't defined")
@@ -58,7 +58,7 @@ after install_accessors => sub {
my $slot = $_[1];
$slot = defined($slot) ? $slot : $handy_default;
@_ = ($_[0]); # Cut it short >8
@_ = ($_[0]); # 8< Cut it short 8<
my $hashref = &{ $read_method_ref };
confess("The attribute doesn't contain a HashRef as it's supposed to")
@@ -9,7 +9,7 @@ use lib("$RealBin/../../lib");
use MonkeyMan;
use MonkeyMan::Constants qw(:version :cloudstack);
use Test::More (tests => 2);
use Test::More (tests => 3);
@@ -20,5 +20,6 @@ my $monkeyman = MonkeyMan->new(
app_version => MM_VERSION
);
ok($monkeyman->_get_cloudstacks->{&MM_PRIMARY_CLOUDSTACK} == $monkeyman->get_cloudstack);
ok($monkeyman->get_cloudstack == $monkeyman->get_cloudstack);
ok($monkeyman->get_cloudstack == $monkeyman->get_cloudstack(&MM_PRIMARY_CLOUDSTACK));
Oops, something went wrong.

0 comments on commit 6267a0a

Please sign in to comment.