Catmandu

 view release on metacpan or  search on metacpan

lib/Catmandu/Cmd/run.pm  view on Meta::CPAN

        ["preprocess|pp", ""],
        ["verbose|v",     ""],
        ["i",             "interactive mode"],
    );
}

sub command {
    my ($self, $opts, $args) = @_;

    if (defined $opts->{i} || !defined $args->[0]) {
        my $pkg = require_package('Catmandu::Interactive');
        my $app = Catmandu::Interactive->new();
        $app->run();
    }
    else {
        my $fix_file = $args->[0];
        $fix_file = [\*STDIN] unless defined $fix_file;

        $opts->{fix} = [$fix_file];

        my $from = Catmandu->importer('Null');

lib/Catmandu/Env.pm  view on Meta::CPAN

        if (my $c = $self->config->{$type}{$key}) {
            check_hash_ref($c);
            check_string(my $package = $c->{package} || $default_package);
            my $opts = check_hash_ref($c->{options} || {});
            if (@_ > 1) {
                $opts = {%$opts, @_};
            }
            elsif (@_ == 1) {
                $opts = {%$opts, %{$_[0]}};
            }
            my $instance = require_package($package, $ns)->new($opts);

            # cache this instance if no arguments are given
            if ($cache && !@_) {
                $cache->{$key} = $instance;
            }

            return $instance;
        }
    }

lib/Catmandu/Fix/Namespace/perl.pm  view on Meta::CPAN


with 'Catmandu::Fix::Namespace';

sub load {
    my ($self, $name, $args, $type) = @_;
    my $ns = join('::', map {camelize($_)} split(/\./, $self->name));
    $ns = join('::', $ns, $type) if $type;

    my $pkg;
    try {
        $pkg = require_package($name, $ns);
    }
    catch_case [
        'Catmandu::NoSuchPackage' => sub {
            Catmandu::NoSuchFixPackage->throw(
                message      => "No such fix package: $name",
                package_name => $_->package_name,
                fix_name     => $name,
            );
        },
    ];

lib/Catmandu/Fix/Parser.pm  view on Meta::CPAN

    my $ns         = $self->get_ns($ns_name)
        // Catmandu::FixParseError->throw("Unknown namespace: $ns_name");
    $ns->load($fix_name, $args, $type);
}

sub _build_ns {
    my ($self, $name) = @_;
    my @name_parts = split(/:/, $name);
    $name = pop @name_parts;
    my $pkg_name = $name_parts[0] // 'perl';
    my $pkg      = require_package($pkg_name, 'Catmandu::Fix::Namespace');
    $pkg->new(name => $name);
}

1;

__END__

=pod

=head1 NAME

lib/Catmandu/Serializer.pm  view on Meta::CPAN

    is      => 'ro',
    lazy    => 1,
    builder => '_build_serializer',
    handles => [qw(serialize deserialize)]
);

sub default_serialization_format {'json'}

sub _build_serializer {
    my ($self) = @_;
    my $pkg = require_package($self->serialization_format,
        'Catmandu::Serializer');
    $pkg->new;
}

# Implementer needs to be create a serializer
# sub serialize {}

# Implementers needs to be create a deserializer
# sub deserialize {}

lib/Catmandu/Store.pm  view on Meta::CPAN


sub new_bag {
    my ($self, $name, $opts) = @_;
    $opts ||= {};
    $opts->{store} = $self;
    $opts->{name}  = $name // $self->default_bag;
    my $default_opts = $self->default_options;
    my $bag_opts     = $self->bag_options->{$opts->{name}} //= {};
    $opts = {%$default_opts, %$bag_opts, %$opts};

    my $pkg = require_package(delete($opts->{class}) // $self->bag_class);
    my $default_plugins = $self->default_plugins;
    my $plugins         = delete($opts->{plugins}) // [];
    if (@$default_plugins || @$plugins) {
        $pkg = $pkg->with_plugins(@$default_plugins, @$plugins);
    }
    $pkg->new($opts);
}

{
    fieldhash my %bag_instances;

lib/Catmandu/Util.pm  view on Meta::CPAN

=head2 Miscellaneous functions

=over 4

=item require_package($pkg)

=item require_package($pkg, $namespace)

Load package C<$pkg> at runtime with C<require> and return it's full name.

    my $pkg = require_package('File::Spec');
    my $dir = $pkg->tmpdir();

    require_package('Util', 'Catmandu');
    # => "Catmandu::Util"
    require_package('Catmandu::Util', 'Catmandu');
    # => "Catmandu::Util"

Throws a Catmandu::Error on failure.

=item use_lib(@dirs)

lib/Catmandu/Util/Path.pm  view on Meta::CPAN

    my ($path) = @_;
    is_string($path) && $path =~ /^\$[\.\/]/ ? 1 : 0;
}

sub as_path {
    my ($path, $path_type) = @_;
    if (is_value($path)) {
        $path_type //= 'simple';
        state $class_cache = {};
        my $class = $class_cache->{$path_type}
            ||= require_package($path_type, 'Catmandu::Path');
        $class->new(path => $path);
    }
    else {
        $path;
    }
}

1;

__END__



( run in 0.311 second using v1.01-cache-2.11-cpan-0d8aa00de5b )