Add headers to Lmo and WebAPI modules, and put the modules in pt-agent.

This commit is contained in:
Daniel Nichter
2012-12-24 18:20:25 -07:00
parent 0083216a6c
commit d035125729
16 changed files with 1779 additions and 93 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -17,15 +17,26 @@
# ########################################################################### # ###########################################################################
# Lmo package # Lmo package
# ########################################################################### # ###########################################################################
{
# Package: Lmo # Package: Lmo
# Lmo provides a miniature object system in the style of Moose and Moo. # Lmo provides a little meta object system like Moose and Moo.
# Forked from 0.30 of Mo. # This code was derived from Mo 0.30.
BEGIN {
$INC{"Lmo.pm"} = __FILE__;
package Lmo; package Lmo;
our $VERSION = '0.01'; our $VERSION = '0.01';
use strict;
use warnings qw( FATAL all );
use Carp ();
use Scalar::Util qw(blessed);
eval {
require Lmo::Meta;
require Lmo::Object;
require Lmo::Types;
};
{ {
# Gets the glob from a given string. # Gets the glob from a given string.
no strict 'refs'; no strict 'refs';
@@ -43,16 +54,6 @@ our $VERSION = '0.01';
} }
} }
use strict;
use warnings qw( FATAL all );
use Carp ();
use Scalar::Util qw(looks_like_number blessed);
use Lmo::Meta;
use Lmo::Object;
use Lmo::Types;
my %export_for; my %export_for;
sub import { sub import {
# Set warnings and strict for the caller. # Set warnings and strict for the caller.
@@ -224,8 +225,6 @@ sub has {
} }
} }
# handles handles # handles handles
sub _has_handles { sub _has_handles {
my ($caller, $attribute, $args) = @_; my ($caller, $attribute, $args) = @_;
@@ -348,8 +347,8 @@ BEGIN {
} }
} }
}
1; 1;
}
# ########################################################################### # ###########################################################################
# End Lmo package # End Lmo package
# ########################################################################### # ###########################################################################

View File

@@ -1,24 +1,42 @@
use strict; # This program is copyright 2012-2013 Percona Inc.
use warnings qw( FATAL all ); # Feedback and improvements are welcome.
#
use Carp (); # THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
use Scalar::Util qw(looks_like_number blessed); # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Lmo::Meta package
# ###########################################################################
{ {
package Lmo::Meta; # Package: Lmo::Meta
my %metadata_for; # Meta data implementation for Lmo. Forked from 0.30 of Mo.
package Lmo::Meta;
sub new { use strict;
shift; use warnings FATAL => 'all';
return Lmo::Meta::Class->new(@_);
}
sub metadata_for {
my $self = shift;
my ($class) = @_;
return $metadata_for{$class} ||= {}; my %metadata_for;
}
sub new {
shift;
return Lmo::Meta::Class->new(@_);
}
sub metadata_for {
my $self = shift;
my ($class) = @_;
return $metadata_for{$class} ||= {};
} }
{ {
@@ -55,3 +73,7 @@ use Scalar::Util qw(looks_like_number blessed);
} }
1; 1;
}
# ###########################################################################
# End Lmo::Meta package
# ###########################################################################

View File

@@ -1,4 +1,24 @@
# Mo::Object is the parent of every Mo-derived object. Here's where new # This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Lmo::Object package
# ###########################################################################
{
# Lmo::Object is the parent of every Mo-derived object. Here's where new
# and BUILDARGS gets inherited from. # and BUILDARGS gets inherited from.
package Lmo::Object; package Lmo::Object;
@@ -6,9 +26,11 @@ use strict;
use warnings qw( FATAL all ); use warnings qw( FATAL all );
use Carp (); use Carp ();
use Scalar::Util qw(looks_like_number blessed); use Scalar::Util qw(blessed);
use Lmo::Meta; eval {
require Lmo::Meta;
};
{ {
# Gets the glob from a given string. # Gets the glob from a given string.
@@ -100,5 +122,8 @@ sub meta {
return Lmo::Meta->new(class => $class); return Lmo::Meta->new(class => $class);
} }
1; 1;
}
# ###########################################################################
# End Lmo::Object package
# ###########################################################################

View File

@@ -1,3 +1,26 @@
# This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Lmo::Types package
# ###########################################################################
{
# Package: Lmo::Types
# Basic types for isa. If you want a new type, either add it here,
# or give isa a coderef.
package Lmo::Types; package Lmo::Types;
use strict; use strict;
@@ -6,9 +29,6 @@ use warnings qw( FATAL all );
use Carp (); use Carp ();
use Scalar::Util qw(looks_like_number blessed); use Scalar::Util qw(looks_like_number blessed);
# Basic types for isa. If you want a new type, either add it here,
# or give isa a coderef.
our %TYPES = ( our %TYPES = (
Bool => sub { !$_[0] || (defined $_[0] && looks_like_number($_[0]) && $_[0] == 1) }, Bool => sub { !$_[0] || (defined $_[0] && looks_like_number($_[0]) && $_[0] == 1) },
Num => sub { defined $_[0] && looks_like_number($_[0]) }, Num => sub { defined $_[0] && looks_like_number($_[0]) },
@@ -96,3 +116,7 @@ sub _nested_constraints {
} }
1; 1;
}
# ###########################################################################
# End Lmo::Types package
# ###########################################################################

View File

@@ -19,8 +19,14 @@
# ########################################################################### # ###########################################################################
{ {
package Percona::Toolkit; package Percona::Toolkit;
our $VERSION = '3.0.0'; our $VERSION = '3.0.0';
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
use Carp qw(carp cluck); use Carp qw(carp cluck);
use Data::Dumper qw(); use Data::Dumper qw();
$Data::Dumper::Indent = 1; $Data::Dumper::Indent = 1;

View File

@@ -1,13 +1,40 @@
# This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Percona::WebAPI::Client package
# ###########################################################################
{
package Percona::WebAPI::Client; package Percona::WebAPI::Client;
our $VERSION = '0.01'; our $VERSION = '0.01';
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
use LWP; use LWP;
use JSON; use JSON;
use Scalar::Util qw(blessed); use Scalar::Util qw(blessed);
use English qw(-no_match_vars); use English qw(-no_match_vars);
use Lmo;
use Percona::Toolkit; use Percona::Toolkit;
use Percona::WebAPI::Exception::Request;
has 'api_key' => ( has 'api_key' => (
is => 'ro', is => 'ro',
@@ -298,4 +325,9 @@ sub update_links {
return; return;
} }
no Lmo;
1; 1;
}
# ###########################################################################
# End Percona::WebAPI::Client package
# ###########################################################################

View File

@@ -1,6 +1,26 @@
# This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Percona::WebAPI::Exception::Request package
# ###########################################################################
{
package Percona::WebAPI::Exception::Request; package Percona::WebAPI::Exception::Request;
use Mo; use Lmo;
use overload '""' => \&as_string; use overload '""' => \&as_string;
has 'method' => ( has 'method' => (
@@ -41,4 +61,9 @@ sub as_string {
$error, $self->status, $self->method, $self->url, $self->content || ''; $error, $self->status, $self->method, $self->url, $self->content || '';
} }
no Lmo;
1; 1;
}
# ###########################################################################
# End Percona::WebAPI::Exception::Request package
# ###########################################################################

View File

@@ -1,6 +1,26 @@
# This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Percona::WebAPI::Representation::HashRef package
# ###########################################################################
{
package Percona::WebAPI::Representation::HashRef; package Percona::WebAPI::Representation::HashRef;
use Moose::Role; use Lmo::Role;
sub as_hashref { sub as_hashref {
my ($self) = @_; my ($self) = @_;
@@ -16,3 +36,7 @@ sub as_hashref {
} }
1; 1;
}
# ###########################################################################
# End Percona::WebAPI::Representation::HashRef package
# ###########################################################################

View File

@@ -1,6 +1,26 @@
# This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Percona::WebAPI::Representation::JSON package
# ###########################################################################
{
package Percona::WebAPI::Representation::JSON; package Percona::WebAPI::Representation::JSON;
use Moose::Role; use Lmo::Role;
use JSON; use JSON;
sub as_json { sub as_json {
@@ -17,3 +37,7 @@ sub as_json {
} }
1; 1;
}
# ###########################################################################
# End Percona::WebAPI::Representation::JSON package
# ###########################################################################

View File

@@ -1,9 +1,26 @@
# This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Percona::WebAPI::Resource::Agent package
# ###########################################################################
{
package Percona::WebAPI::Resource::Agent; package Percona::WebAPI::Resource::Agent;
use Mo; use Lmo;
with 'Percona::WebAPI::Representation::JSON';
with 'Percona::WebAPI::Representation::HashRef';
has 'id' => ( has 'id' => (
is => 'ro', is => 'ro',
@@ -24,4 +41,9 @@ has 'versions' => (
default => undef, default => undef,
); );
no Lmo;
1; 1;
}
# ###########################################################################
# End Percona::WebAPI::Resource::Agent package
# ###########################################################################

View File

@@ -1,9 +1,26 @@
# This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Percona::WebAPI::Resource::Config package
# ###########################################################################
{
package Percona::WebAPI::Resource::Config; package Percona::WebAPI::Resource::Config;
use Mo; use Lmo;
with 'Percona::WebAPI::Representation::JSON';
with 'Percona::WebAPI::Representation::HashRef';
has 'options' => ( has 'options' => (
is => 'ro', is => 'ro',
@@ -11,4 +28,9 @@ has 'options' => (
required => 1, required => 1,
); );
no Lmo;
1; 1;
}
# ###########################################################################
# End Percona::WebAPI::Resource::Config package
# ###########################################################################

View File

@@ -1,9 +1,26 @@
# This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Percona::WebAPI::Resource::Run package
# ###########################################################################
{
package Percona::WebAPI::Resource::Run; package Percona::WebAPI::Resource::Run;
use Mo; use Lmo;
with 'Percona::WebAPI::Representation::JSON';
with 'Percona::WebAPI::Representation::HashRef';
has 'number' => ( has 'number' => (
is => 'ro', is => 'ro',
@@ -29,4 +46,9 @@ has 'output' => (
required => 1, required => 1,
); );
no Lmo;
1; 1;
}
# ###########################################################################
# End Percona::WebAPI::Resource::Run package
# ###########################################################################

View File

@@ -1,9 +1,26 @@
# This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
# licenses.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Percona::WebAPI::Resource::Service package
# ###########################################################################
{
package Percona::WebAPI::Resource::Service; package Percona::WebAPI::Resource::Service;
use Mo; use Lmo;
with 'Percona::WebAPI::Representation::JSON';
with 'Percona::WebAPI::Representation::HashRef';
has 'name' => ( has 'name' => (
is => 'ro', is => 'ro',
@@ -23,4 +40,9 @@ has 'run' => (
required => 1, required => 1,
); );
no Lmo;
1; 1;
}
# ###########################################################################
# End Percona::WebAPI::Resource::Service package
# ###########################################################################

View File

@@ -1,4 +1,4 @@
# This program is copyright 2012 Percona Inc. # This program is copyright 2012-2013 Percona Inc.
# Feedback and improvements are welcome. # Feedback and improvements are welcome.
# #
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED # THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED

View File

@@ -22,7 +22,7 @@
# VersionParser parses a MySQL version string. # VersionParser parses a MySQL version string.
package VersionParser; package VersionParser;
use Mo; use Lmo;
use Scalar::Util qw(blessed); use Scalar::Util qw(blessed);
use English qw(-no_match_vars); use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0; use constant PTDEBUG => $ENV{PTDEBUG} || 0;
@@ -37,8 +37,6 @@ use overload (
use Carp (); use Carp ();
our $VERSION = 0.01;
has major => ( has major => (
is => 'ro', is => 'ro',
isa => 'Int', isa => 'Int',
@@ -213,7 +211,7 @@ sub _d {
print STDERR "# $package:$line $PID ", join(' ', @_), "\n"; print STDERR "# $package:$line $PID ", join(' ', @_), "\n";
} }
no Mo; no Lmo;
1; 1;
} }
# ########################################################################### # ###########################################################################