DBIx-ObjectMapper
view release on metacpan or search on metacpan
inc/Spiffy.pm view on Meta::CPAN
sub_start =>
"sub {\n",
set_default =>
" \$_[0]->{%s} = %s\n unless exists \$_[0]->{%s};\n",
init =>
" return \$_[0]->{%s} = do { my \$self = \$_[0]; %s }\n" .
" unless \$#_ > 0 or defined \$_[0]->{%s};\n",
weak_init =>
" return do {\n" .
" \$_[0]->{%s} = do { my \$self = \$_[0]; %s };\n" .
" Scalar::Util::weaken(\$_[0]->{%s}) if ref \$_[0]->{%s};\n" .
" \$_[0]->{%s};\n" .
" } unless \$#_ > 0 or defined \$_[0]->{%s};\n",
return_if_get =>
" return \$_[0]->{%s} unless \$#_ > 0;\n",
set =>
" \$_[0]->{%s} = \$_[1];\n",
weaken =>
" Scalar::Util::weaken(\$_[0]->{%s}) if ref \$_[0]->{%s};\n",
sub_end =>
" return \$_[0]->{%s};\n}\n",
);
sub field {
my $package = caller;
my ($args, @values) = do {
no warnings;
local *boolean_arguments = sub { (qw(-weak)) };
local *paired_arguments = sub { (qw(-package -init)) };
Spiffy->parse_arguments(@_);
};
my ($field, $default) = @values;
$package = $args->{-package} if defined $args->{-package};
die "Cannot have a default for a weakened field ($field)"
if defined $default && $args->{-weak};
return if defined &{"${package}::$field"};
require Scalar::Util if $args->{-weak};
my $default_string =
( ref($default) eq 'ARRAY' and not @$default )
? '[]'
: (ref($default) eq 'HASH' and not keys %$default )
? '{}'
: default_as_code($default);
my $code = $code{sub_start};
if ($args->{-init}) {
my $fragment = $args->{-weak} ? $code{weak_init} : $code{init};
$code .= sprintf $fragment, $field, $args->{-init}, ($field) x 4;
}
$code .= sprintf $code{set_default}, $field, $default_string, $field
if defined $default;
$code .= sprintf $code{return_if_get}, $field;
$code .= sprintf $code{set}, $field;
$code .= sprintf $code{weaken}, $field, $field
if $args->{-weak};
$code .= sprintf $code{sub_end}, $field;
my $sub = eval $code;
die $@ if $@;
no strict 'refs';
*{"${package}::$field"} = $sub;
return $code if defined wantarray;
}
lib/DBIx/ObjectMapper/Mapper.pm view on Meta::CPAN
package DBIx::ObjectMapper::Mapper;
use strict;
use warnings;
use Carp::Clan qw/^DBIx::ObjectMapper/;
use List::MoreUtils;
use Scalar::Util qw(blessed weaken);
use Digest::MD5 qw(md5_hex);
use Params::Validate qw(:all);
use Class::MOP;
use Class::MOP::Class;
use Log::Any qw($log);
use DBIx::ObjectMapper::Utils;
use DBIx::ObjectMapper::Mapper::Instance;
use DBIx::ObjectMapper::Mapper::Constructor;
use DBIx::ObjectMapper::Mapper::Accessor;
lib/DBIx/ObjectMapper/Mapper/Attribute/Property.pm view on Meta::CPAN
package DBIx::ObjectMapper::Mapper::Attribute::Property;
use strict;
use warnings;
use Carp::Clan qw/^DBIx::ObjectMapper/;
use Params::Validate qw(:all);
use Scalar::Util qw(weaken);
my @TYPES = qw(column relation);
sub new {
my $class = shift;
my %prop = validate(
@_,
{
isa => +{
type => OBJECT,
lib/DBIx/ObjectMapper/Mapper/Instance.pm view on Meta::CPAN
package DBIx::ObjectMapper::Mapper::Instance;
use strict;
use warnings;
use Carp::Clan qw/^DBIx::ObjectMapper/;
use Try::Tiny;
use Scalar::Util qw(refaddr weaken);
use Log::Any qw($log);
use DBIx::ObjectMapper::Utils;
use DBIx::ObjectMapper::Session::Array;
our $call = 0;
my %INSTANCES;
my %STATUS = (
# "status" => "changable status"
transient => [ 'pending', 'persistent', 'detached' ],
pending => [ 'expired', 'detached' ],
lib/DBIx/ObjectMapper/Session/Array.pm view on Meta::CPAN
package DBIx::ObjectMapper::Session::Array;
use strict;
use warnings;
use Scalar::Util qw(refaddr weaken);
use base qw(Tie::Array);
sub new {
my ( $class, $name, $mapper, @val ) = @_;
my $array = [];
tie @$array, $class, $name, $mapper, \@val;
return $array;
}
sub TIEARRAY {
t/12_session/020_share_object.t view on Meta::CPAN
my $self = shift;
$self->{children} = shift if @_;
return $self->{children};
}
1;
};
{
package MyTest20::Child;
use Scalar::Util qw(weaken isweak);
sub new {
my $class = shift;
my %param = @_ % 2 == 0 ? @_ : %{$_[0]};
my $self = bless \%param, $class;
weaken $self->{parent};
return $self;
}
sub id {
my $self = shift;
$self->{id} = shift if @_;
$self->{id};
}
sub parent_id {
t/12_session/020_share_object.t view on Meta::CPAN
$self->{parent_id} = shift;
}
$self->{parent_id};
}
sub parent {
my $self = shift;
if( @_ ) {
$self->{parent} = shift;
}
weaken $self->{parent} unless isweak $self->{parent};
$self->{parent};
}
1;
};
$mapper->maps(
$mapper->metadata->t('parent') => 'MyTest20::Parent',
attributes => {
properties => {
( run in 0.374 second using v1.01-cache-2.11-cpan-65fba6d93b7 )