Skip to content

Commit

Permalink
improve tests for message
Browse files Browse the repository at this point in the history
  • Loading branch information
zigorou committed Sep 2, 2009
1 parent 1bf5883 commit 4118f4c
Show file tree
Hide file tree
Showing 16 changed files with 552 additions and 126 deletions.
30 changes: 24 additions & 6 deletions lib/Data/OpenSocial/Base.pm
Expand Up @@ -12,32 +12,50 @@ for (
__PACKAGE__->mk_classdata($_);
}

__PACKAGE__->element_fields([]);
__PACKAGE__->element_to_field_map(+{});
__PACKAGE__->field_to_element_map(+{});
__PACKAGE__->namespaces(
+{
'http://ns.opensocial.org/2008/opensocial' => 'os',
'http://opensocial.org/2008/opensocialapi' => 'osapi',
'http://www.w3.org/2005/Atom' => 'atom',
'http://a9.com/-/spec/opensearch/1.1' => 'osearch',
},
);
__PACKAGE__->field_to_namespace_map(+{});

sub setup {
my ( $class, @element_fields ) = @_;

$class->element_fields( [ map { $_->{field} } @element_fields ] );
$class->element_fields( [ ( @{$class->element_fields}, map { $_->{field} } @element_fields ) ] );
$class->element_to_field_map(
+{
map { @$_{qw/typemap field/} }
grep { exists $_->{typemap} } @element_fields
%{$class->element_to_field_map},
(
map { @$_{qw/typemap field/} }
grep { exists $_->{typemap} } @element_fields
),
}
);
$class->field_to_element_map(
+{
map { @$_{qw/field typemap/} }
grep { exists $_->{typemap} } @element_fields
%{$class->field_to_element_map},
(
map { @$_{qw/field typemap/} }
grep { exists $_->{typemap} } @element_fields
),
}
);
$class->field_to_namespace_map(
+{ map { ( $_->{field}, $_->{namespace} ) } @element_fields } );
+{
%{ $class->field_to_namespace_map },
(
map { ( $_->{field}, $_->{namespace} ) }
@element_fields
)
},
);

return map {
my $attr = $_;
Expand Down
9 changes: 4 additions & 5 deletions lib/Data/OpenSocial/Format/JSON.pm
Expand Up @@ -6,9 +6,8 @@ use JSON::Any qw(DWIW XS Syck JSON);
use Data::Util qw(is_array_ref is_hash_ref);
use DateTime::Format::ISO8601;
use Data::OpenSocial::Types;

# use Module::Load;
# use Module::Loaded;
use Module::Load;
use Module::Loaded;

sub format {
my ( $class, $object ) = @_;
Expand Down Expand Up @@ -96,8 +95,6 @@ sub parse {
sub parse_object {
my ( $class, $class_type, $object ) = @_;

load $class_type unless ( is_loaded $class_type);

if ( UNIVERSAL::isa( $class_type, 'Data::OpenSocial::Appdata' )
&& !exists $object->{entry} )
{
Expand All @@ -111,6 +108,8 @@ sub parse_object {
}
}

load $class_type unless (is_loaded($class_type));

my %data;
for my $element ( keys %$object ) {
my $field = $class_type->element_to_field($element);
Expand Down
11 changes: 10 additions & 1 deletion lib/Data/OpenSocial/MediaItem.pm
Expand Up @@ -36,6 +36,7 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'thumbnail_url',
typemap => 'thumbnailUrl',
is => 'rw',
isa => 'Str',
required => 0,
Expand Down Expand Up @@ -71,20 +72,23 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'album_id',
typemap => 'albumId',
is => 'rw',
isa => 'Str',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'file_size',
typemap => 'fileSize',
is => 'rw',
isa => 'Int',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'start_time',
typemap => 'startTime',
is => 'rw',
isa => 'DateTime',
required => 0,
Expand All @@ -99,20 +103,23 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'num_votes',
typemap => 'numVotes',
is => 'rw',
isa => 'Int',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'num_comments',
typemap => 'numComments',
is => 'rw',
isa => 'Int',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'num_views',
typemap => 'numViews',
is => 'rw',
isa => 'Int',
required => 0,
Expand All @@ -127,13 +134,15 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'tagged_people',
typemap => 'taggedPeople',
is => 'rw',
isa => 'Str',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'mime_type',
typemap => 'mimeType',
is => 'rw',
isa => 'Str',
required => 0,
Expand All @@ -142,7 +151,7 @@ do {
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'type',
is => 'rw',
isa => 'MediaItemType',
isa => 'OpenSocial.MediaItemType',
required => 0,
},
+{
Expand Down
28 changes: 23 additions & 5 deletions lib/Data/OpenSocial/Message.pm
Expand Up @@ -4,7 +4,11 @@ use Any::Moose;
use Any::Moose ( 'X::Types::DateTime' => [qw/DateTime/], );
use Any::Moose 'X::AttributeHelpers';

use Data::OpenSocial::Types qw(OpenSocial.Url);
use Data::OpenSocial::Types qw(
OpenSocial.Url
OpenSocial.Url.Collection
OpenSocial.MessageType
);

extends 'Data::OpenSocial::Base';

Expand All @@ -20,6 +24,7 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'body_id',
typemap => 'bodyId',
is => 'rw',
isa => 'Str',
required => 0,
Expand All @@ -34,6 +39,7 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'title_id',
typemap => 'titleId',
is => 'rw',
isa => 'Str',
required => 0,
Expand All @@ -49,19 +55,21 @@ do {
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'recipients',
is => 'rw',
isa => 'Str',
isa => 'ArrayRef[Str]',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'sender_id',
typemap => 'senderId',
is => 'rw',
isa => 'Str',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'time_sent',
typemap => 'timeSent',
is => 'rw',
isa => 'DateTime',
required => 0,
Expand All @@ -70,6 +78,7 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'in_reply_to',
typemap => 'inReplyTo',
is => 'rw',
isa => 'Str',
required => 0,
Expand All @@ -78,7 +87,7 @@ do {
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'replies',
is => 'rw',
isa => 'Str',
isa => 'ArrayRef[Str]',
required => 0,
},
+{
Expand All @@ -91,15 +100,17 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'app_url',
typemap => 'appUrl',
is => 'rw',
isa => 'Str',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'collection_ids',
typemap => 'collectionIds',
is => 'rw',
isa => 'Str',
isa => 'ArrayRef[Str]',
required => 0,
},
+{
Expand All @@ -115,11 +126,18 @@ do {
field => 'urls',
metaclass => 'Collection::List',
is => 'rw',
isa => 'ArrayRef[OpenSocial.Url]',
isa => 'OpenSocial.Url.Collection',
required => 0,
provides => +{ count => 'count_urls', },
coerce => 1,
},
+{ ### specs is wrong
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'type',
is => 'rw',
isa => 'OpenSocial.MessageType',
required => 0,
}
);

my %attrs = __PACKAGE__->setup(@element_fields);
Expand Down
37 changes: 0 additions & 37 deletions lib/Data/OpenSocial/MessageType.pm

This file was deleted.

0 comments on commit 4118f4c

Please sign in to comment.